TUN-4081: Update log severities to use Zerolog's levels
This commit is contained in:
parent
954cd6adca
commit
2c746b3361
|
@ -164,7 +164,7 @@ func Commands() []*cli.Command {
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: logger.LogSSHLevelFlag,
|
Name: logger.LogSSHLevelFlag,
|
||||||
Aliases: []string{"loglevel"}, //added to match the tunnel side
|
Aliases: []string{"loglevel"}, //added to match the tunnel side
|
||||||
Usage: "Application logging level {fatal, error, info, debug}. ",
|
Usage: "Application logging level {debug, info, warn, error, fatal}. ",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: sshConnectTo,
|
Name: sshConnectTo,
|
||||||
|
@ -296,7 +296,6 @@ func curl(c *cli.Context) error {
|
||||||
return run("curl", cmdArgs...)
|
return run("curl", cmdArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// run kicks off a shell task and pipe the results to the respective std pipes
|
// run kicks off a shell task and pipe the results to the respective std pipes
|
||||||
func run(cmd string, args ...string) error {
|
func run(cmd string, args ...string) error {
|
||||||
c := exec.Command(cmd, args...)
|
c := exec.Command(cmd, args...)
|
||||||
|
|
|
@ -75,8 +75,8 @@ const (
|
||||||
// uiFlag is to enable launching cloudflared in interactive UI mode
|
// uiFlag is to enable launching cloudflared in interactive UI mode
|
||||||
uiFlag = "ui"
|
uiFlag = "ui"
|
||||||
|
|
||||||
debugLevelWarning = "At debug level, request URL, method, protocol, content legnth and header will be logged. " +
|
debugLevelWarning = "At debug level cloudflared will log request URL, method, protocol, content length, as well as, all request and response headers. " +
|
||||||
"Response status, content length and header will also be logged in debug level."
|
"This can expose sensitive information in your logs."
|
||||||
|
|
||||||
LogFieldCommand = "command"
|
LogFieldCommand = "command"
|
||||||
LogFieldExpandedPath = "expandedPath"
|
LogFieldExpandedPath = "expandedPath"
|
||||||
|
@ -920,7 +920,7 @@ func configureLoggingFlags(shouldHide bool) []cli.Flag {
|
||||||
altsrc.NewStringFlag(&cli.StringFlag{
|
altsrc.NewStringFlag(&cli.StringFlag{
|
||||||
Name: logger.LogLevelFlag,
|
Name: logger.LogLevelFlag,
|
||||||
Value: "info",
|
Value: "info",
|
||||||
Usage: "Application logging level {fatal, error, info, debug}. " + debugLevelWarning,
|
Usage: "Application logging level {debug, info, warn, error, fatal}. " + debugLevelWarning,
|
||||||
EnvVars: []string{"TUNNEL_LOGLEVEL"},
|
EnvVars: []string{"TUNNEL_LOGLEVEL"},
|
||||||
Hidden: shouldHide,
|
Hidden: shouldHide,
|
||||||
}),
|
}),
|
||||||
|
@ -928,7 +928,7 @@ func configureLoggingFlags(shouldHide bool) []cli.Flag {
|
||||||
Name: logger.LogTransportLevelFlag,
|
Name: logger.LogTransportLevelFlag,
|
||||||
Aliases: []string{"proto-loglevel"}, // This flag used to be called proto-loglevel
|
Aliases: []string{"proto-loglevel"}, // This flag used to be called proto-loglevel
|
||||||
Value: "info",
|
Value: "info",
|
||||||
Usage: "Transport logging level(previously called protocol logging level) {fatal, error, info, debug}",
|
Usage: "Transport logging level(previously called protocol logging level) {debug, info, warn, error, fatal}",
|
||||||
EnvVars: []string{"TUNNEL_PROTO_LOGLEVEL", "TUNNEL_TRANSPORT_LOGLEVEL"},
|
EnvVars: []string{"TUNNEL_PROTO_LOGLEVEL", "TUNNEL_TRANSPORT_LOGLEVEL"},
|
||||||
Hidden: shouldHide,
|
Hidden: shouldHide,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -64,6 +64,8 @@ func (t resilientMultiWriter) Write(p []byte) (n int, err error) {
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var levelErrorLogged = false
|
||||||
|
|
||||||
func newZerolog(loggerConfig *Config) *zerolog.Logger {
|
func newZerolog(loggerConfig *Config) *zerolog.Logger {
|
||||||
var writers []io.Writer
|
var writers []io.Writer
|
||||||
|
|
||||||
|
@ -91,11 +93,15 @@ func newZerolog(loggerConfig *Config) *zerolog.Logger {
|
||||||
|
|
||||||
multi := resilientMultiWriter{writers}
|
multi := resilientMultiWriter{writers}
|
||||||
|
|
||||||
level, err := zerolog.ParseLevel(loggerConfig.MinLevel)
|
level, levelErr := zerolog.ParseLevel(loggerConfig.MinLevel)
|
||||||
if err != nil {
|
if levelErr != nil {
|
||||||
return fallbackLogger(err)
|
level = zerolog.InfoLevel
|
||||||
}
|
}
|
||||||
log := zerolog.New(multi).With().Timestamp().Logger().Level(level)
|
log := zerolog.New(multi).With().Timestamp().Logger().Level(level)
|
||||||
|
if !levelErrorLogged && levelErr != nil {
|
||||||
|
log.Error().Msgf("Failed to parse log level %q, using %q instead", loggerConfig.MinLevel, level)
|
||||||
|
levelErrorLogged = true
|
||||||
|
}
|
||||||
|
|
||||||
return &log
|
return &log
|
||||||
}
|
}
|
||||||
|
@ -151,8 +157,8 @@ func Create(loggerConfig *Config) *zerolog.Logger {
|
||||||
func createConsoleLogger(config ConsoleConfig) io.Writer {
|
func createConsoleLogger(config ConsoleConfig) io.Writer {
|
||||||
consoleOut := os.Stderr
|
consoleOut := os.Stderr
|
||||||
return zerolog.ConsoleWriter{
|
return zerolog.ConsoleWriter{
|
||||||
Out: colorable.NewColorable(consoleOut),
|
Out: colorable.NewColorable(consoleOut),
|
||||||
NoColor: config.noColor || !term.IsTerminal(int(consoleOut.Fd())),
|
NoColor: config.noColor || !term.IsTerminal(int(consoleOut.Fd())),
|
||||||
TimeFormat: consoleTimeFormat,
|
TimeFormat: consoleTimeFormat,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue