MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / createFromContext

Function createFromContext

logger/create.go:143–176  ·  view source on GitHub ↗
(
	c *cli.Context,
	logLevelFlagName,
	logDirectoryFlagName string,
	disableTerminal bool,
)

Source from the content-addressed store, hash-verified

141}
142
143func createFromContext(
144 c *cli.Context,
145 logLevelFlagName,
146 logDirectoryFlagName string,
147 disableTerminal bool,
148) *zerolog.Logger {
149 logLevel := c.String(logLevelFlagName)
150 logFile := c.String(cfdflags.LogFile)
151 logDirectory := c.String(logDirectoryFlagName)
152 var logFormatJSON bool
153 switch c.String(cfdflags.LogFormatOutput) {
154 case cfdflags.LogFormatOutputValueJSON:
155 logFormatJSON = true
156 case cfdflags.LogFormatOutputValueDefault:
157 // "default" and unset use the same logger output format
158 fallthrough
159 default:
160 logFormatJSON = false
161 }
162
163 loggerConfig := CreateConfig(
164 logLevel,
165 disableTerminal,
166 logFormatJSON,
167 logDirectory,
168 logFile,
169 )
170
171 log := newZerolog(loggerConfig)
172 if incompatibleFlagsSet := logFile != "" && logDirectory != ""; incompatibleFlagsSet {
173 log.Error().Msgf("Your config includes values for both %s (%s) and %s (%s), but they are incompatible. %s takes precedence.", cfdflags.LogFile, logFile, logDirectoryFlagName, logDirectory, cfdflags.LogFile)
174 }
175 return log
176}
177
178func Create(loggerConfig *Config) *zerolog.Logger {
179 if loggerConfig == nil {

Callers 3

CreateLoggerFromContextFunction · 0.85

Calls 4

CreateConfigFunction · 0.85
newZerologFunction · 0.85
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected