Skip to content

Commit 2c746b3

Browse files
adamchalmersipostelnik
authored andcommitted
TUN-4081: Update log severities to use Zerolog's levels
1 parent 954cd6a commit 2c746b3

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

cmd/cloudflared/access/cmd.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Add to your {{.Home}}/.ssh/config:
4040
4141
Host {{.Hostname}}
4242
{{- if .ShortLivedCerts}}
43-
ProxyCommand bash -c '{{.Cloudflared}} access ssh-gen --hostname %h; ssh -tt %r@cfpipe-{{.Hostname}} >&2 <&1'
43+
ProxyCommand bash -c '{{.Cloudflared}} access ssh-gen --hostname %h; ssh -tt %r@cfpipe-{{.Hostname}} >&2 <&1'
4444
4545
Host cfpipe-{{.Hostname}}
4646
HostName {{.Hostname}}
@@ -77,9 +77,9 @@ func Commands() []*cli.Command {
7777
Aliases: []string{"forward"},
7878
Category: "Access",
7979
Usage: "access <subcommand>",
80-
Description: `Cloudflare Access protects internal resources by securing, authenticating and monitoring access
81-
per-user and by application. With Cloudflare Access, only authenticated users with the required permissions are
82-
able to reach sensitive resources. The commands provided here allow you to interact with Access protected
80+
Description: `Cloudflare Access protects internal resources by securing, authenticating and monitoring access
81+
per-user and by application. With Cloudflare Access, only authenticated users with the required permissions are
82+
able to reach sensitive resources. The commands provided here allow you to interact with Access protected
8383
applications from the command line.`,
8484
Subcommands: []*cli.Command{
8585
{
@@ -89,7 +89,7 @@ func Commands() []*cli.Command {
8989
Description: `The login subcommand initiates an authentication flow with your identity provider.
9090
The subcommand will launch a browser. For headless systems, a url is provided.
9191
Once authenticated with your identity provider, the login command will generate a JSON Web Token (JWT)
92-
scoped to your identity, the application you intend to reach, and valid for a session duration set by your
92+
scoped to your identity, the application you intend to reach, and valid for a session duration set by your
9393
administrator. cloudflared stores the token in local storage.`,
9494
Flags: []cli.Flag{
9595
&cli.StringFlag{
@@ -164,7 +164,7 @@ func Commands() []*cli.Command {
164164
&cli.StringFlag{
165165
Name: logger.LogSSHLevelFlag,
166166
Aliases: []string{"loglevel"}, //added to match the tunnel side
167-
Usage: "Application logging level {fatal, error, info, debug}. ",
167+
Usage: "Application logging level {debug, info, warn, error, fatal}. ",
168168
},
169169
&cli.StringFlag{
170170
Name: sshConnectTo,
@@ -296,7 +296,6 @@ func curl(c *cli.Context) error {
296296
return run("curl", cmdArgs...)
297297
}
298298

299-
300299
// run kicks off a shell task and pipe the results to the respective std pipes
301300
func run(cmd string, args ...string) error {
302301
c := exec.Command(cmd, args...)

cmd/cloudflared/tunnel/cmd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ const (
7575
// uiFlag is to enable launching cloudflared in interactive UI mode
7676
uiFlag = "ui"
7777

78-
debugLevelWarning = "At debug level, request URL, method, protocol, content legnth and header will be logged. " +
79-
"Response status, content length and header will also be logged in debug level."
78+
debugLevelWarning = "At debug level cloudflared will log request URL, method, protocol, content length, as well as, all request and response headers. " +
79+
"This can expose sensitive information in your logs."
8080

8181
LogFieldCommand = "command"
8282
LogFieldExpandedPath = "expandedPath"
@@ -920,15 +920,15 @@ func configureLoggingFlags(shouldHide bool) []cli.Flag {
920920
altsrc.NewStringFlag(&cli.StringFlag{
921921
Name: logger.LogLevelFlag,
922922
Value: "info",
923-
Usage: "Application logging level {fatal, error, info, debug}. " + debugLevelWarning,
923+
Usage: "Application logging level {debug, info, warn, error, fatal}. " + debugLevelWarning,
924924
EnvVars: []string{"TUNNEL_LOGLEVEL"},
925925
Hidden: shouldHide,
926926
}),
927927
altsrc.NewStringFlag(&cli.StringFlag{
928928
Name: logger.LogTransportLevelFlag,
929929
Aliases: []string{"proto-loglevel"}, // This flag used to be called proto-loglevel
930930
Value: "info",
931-
Usage: "Transport logging level(previously called protocol logging level) {fatal, error, info, debug}",
931+
Usage: "Transport logging level(previously called protocol logging level) {debug, info, warn, error, fatal}",
932932
EnvVars: []string{"TUNNEL_PROTO_LOGLEVEL", "TUNNEL_TRANSPORT_LOGLEVEL"},
933933
Hidden: shouldHide,
934934
}),

logger/create.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ func (t resilientMultiWriter) Write(p []byte) (n int, err error) {
6464
return len(p), nil
6565
}
6666

67+
var levelErrorLogged = false
68+
6769
func newZerolog(loggerConfig *Config) *zerolog.Logger {
6870
var writers []io.Writer
6971

@@ -91,11 +93,15 @@ func newZerolog(loggerConfig *Config) *zerolog.Logger {
9193

9294
multi := resilientMultiWriter{writers}
9395

94-
level, err := zerolog.ParseLevel(loggerConfig.MinLevel)
95-
if err != nil {
96-
return fallbackLogger(err)
96+
level, levelErr := zerolog.ParseLevel(loggerConfig.MinLevel)
97+
if levelErr != nil {
98+
level = zerolog.InfoLevel
9799
}
98100
log := zerolog.New(multi).With().Timestamp().Logger().Level(level)
101+
if !levelErrorLogged && levelErr != nil {
102+
log.Error().Msgf("Failed to parse log level %q, using %q instead", loggerConfig.MinLevel, level)
103+
levelErrorLogged = true
104+
}
99105

100106
return &log
101107
}
@@ -151,8 +157,8 @@ func Create(loggerConfig *Config) *zerolog.Logger {
151157
func createConsoleLogger(config ConsoleConfig) io.Writer {
152158
consoleOut := os.Stderr
153159
return zerolog.ConsoleWriter{
154-
Out: colorable.NewColorable(consoleOut),
155-
NoColor: config.noColor || !term.IsTerminal(int(consoleOut.Fd())),
160+
Out: colorable.NewColorable(consoleOut),
161+
NoColor: config.noColor || !term.IsTerminal(int(consoleOut.Fd())),
156162
TimeFormat: consoleTimeFormat,
157163
}
158164
}

0 commit comments

Comments
 (0)