@@ -157,6 +157,8 @@ func ConfigureWithOutputs(defaultLoggerCfg Config, outputs ...zapcore.Core) erro
157157// only used to set selectors and level.  This is useful if a part of 
158158// your code uses logp but the log output is already handled.  Normal 
159159// use cases should use Configure or ConfigureWithOutput. 
160+ // 
161+ // Deprecated: Prefer using localized loggers. Use logp.ConfigureWithCoreLocal. 
160162func  ConfigureWithCore (loggerCfg  Config , core  zapcore.Core ) error  {
161163	var  (
162164		sink   zapcore.Core 
@@ -202,6 +204,56 @@ func ConfigureWithCore(loggerCfg Config, core zapcore.Core) error {
202204	return  nil 
203205}
204206
207+ // ConfigureWithCoreLocal returns a logger using passed in 
208+ // core.  It is assumed that an output has already been defined with 
209+ // the core and a new one should not be created.  The loggerCfg is 
210+ // only used to set selectors and level. 
211+ func  ConfigureWithCoreLocal (loggerCfg  Config , core  zapcore.Core ) (* Logger , error ) {
212+ 	var  (
213+ 		sink   zapcore.Core 
214+ 		level  zap.AtomicLevel 
215+ 	)
216+ 
217+ 	level  =  zap .NewAtomicLevelAt (loggerCfg .Level .ZapLevel ())
218+ 
219+ 	if  loggerCfg .WithFields  !=  nil  {
220+ 		fields  :=  make ([]zapcore.Field , 0 , len (loggerCfg .WithFields ))
221+ 		for  key , value  :=  range  loggerCfg .WithFields  {
222+ 			fields  =  append (fields , zap .Any (key , value ))
223+ 		}
224+ 		core  =  core .With (fields )
225+ 	}
226+ 
227+ 	sink  =  wrappedCore (core )
228+ 
229+ 	// Enabled selectors when debug is enabled. 
230+ 	selectors  :=  make (map [string ]struct {}, len (loggerCfg .Selectors ))
231+ 	if  loggerCfg .Level .Enabled (DebugLevel ) &&  len (loggerCfg .Selectors ) >  0  {
232+ 		for  _ , sel  :=  range  loggerCfg .Selectors  {
233+ 			selectors [strings .TrimSpace (sel )] =  struct {}{}
234+ 		}
235+ 
236+ 		// Default to all enabled if no selectors are specified. 
237+ 		if  len (selectors ) ==  0  {
238+ 			selectors ["*" ] =  struct {}{}
239+ 		}
240+ 
241+ 		sink  =  selectiveWrapper (sink , selectors )
242+ 	}
243+ 
244+ 	root  :=  zap .New (sink , makeOptions (loggerCfg )... )
245+ 	// TODO: Remove this when there is no more global logger dependency 
246+ 	storeLogger (& coreLogger {
247+ 		selectors :    selectors ,
248+ 		rootLogger :   root ,
249+ 		globalLogger : root .WithOptions (zap .AddCallerSkip (1 )),
250+ 		logger :       newLogger (root , "" ),
251+ 		level :        level ,
252+ 		observedLogs : nil ,
253+ 	})
254+ 	return  newLogger (root , "" ), nil 
255+ }
256+ 
205257// ConfigureWithTypedOutput configures the global logger to use typed outputs. 
206258// 
207259// If a log entry matches the defined key/value, this entry is logged using the 
@@ -219,6 +271,8 @@ func ConfigureWithCore(loggerCfg Config, core zapcore.Core) error {
219271// 
220272// If `defaultLoggerCfg.toObserver` is true, then `typedLoggerCfg` is ignored 
221273// and a single sink is used so all logs can be observed. 
274+ // 
275+ // Deprecated: Prefer using localized loggers. Use logp.ConfigureWithTypedOutputLocal. 
222276func  ConfigureWithTypedOutput (defaultLoggerCfg , typedLoggerCfg  Config , key , value  string , outputs  ... zapcore.Core ) error  {
223277	sink , level , observedLogs , selectors , err  :=  createSink (defaultLoggerCfg , outputs ... )
224278	if  err  !=  nil  {
@@ -256,6 +310,57 @@ func ConfigureWithTypedOutput(defaultLoggerCfg, typedLoggerCfg Config, key, valu
256310	return  nil 
257311}
258312
313+ // ConfigureWithTypedOutputLocal returns a logger that uses typed outputs. 
314+ // 
315+ // If a log entry matches the defined key/value, this entry is logged using the 
316+ // core generated from `typedLoggerCfg`, otherwise it will be logged by all 
317+ // cores in `outputs` and the one generated from `defaultLoggerCfg`. 
318+ // Arguments: 
319+ //   - `defaultLoggerCfg` is used to create a new core that will be the default 
320+ //     output from the logger 
321+ //   - `typedLoggerCfg` is used to create a new output that will only be used 
322+ //     when the log entry matches `entry[logKey] = kind` 
323+ //   - `key` is the key the typed logger will look at 
324+ //   - `value` is the value compared against the `logKey` entry 
325+ //   - `outputs` is a list of cores that will be added together with the core 
326+ //     generated by `defaultLoggerCfg` as the default output for the loggger. 
327+ func  ConfigureWithTypedOutputLocal (defaultLoggerCfg , typedLoggerCfg  Config , key , value  string , outputs  ... zapcore.Core ) (* Logger , error ) {
328+ 	sink , level , observedLogs , selectors , err  :=  createSink (defaultLoggerCfg , outputs ... )
329+ 	if  err  !=  nil  {
330+ 		return  nil , err 
331+ 	}
332+ 
333+ 	var  typedCore  zapcore.Core 
334+ 	typedCore , err  =  createLogOutput (typedLoggerCfg , level )
335+ 
336+ 	if  err  !=  nil  {
337+ 		return  nil , fmt .Errorf ("could not create typed logger output: %w" , err )
338+ 	}
339+ 
340+ 	sink  =  & typedLoggerCore {
341+ 		defaultCore : sink ,
342+ 		typedCore :   typedCore ,
343+ 		key :         key ,
344+ 		value :       value ,
345+ 	}
346+ 
347+ 	sink  =  selectiveWrapper (sink , selectors )
348+ 
349+ 	root  :=  zap .New (sink , makeOptions (defaultLoggerCfg )... )
350+ 
351+ 	// TODO: Remove this when there is no more global logger dependency 
352+ 	storeLogger (& coreLogger {
353+ 		selectors :    selectors ,
354+ 		rootLogger :   root ,
355+ 		globalLogger : root .WithOptions (zap .AddCallerSkip (1 )),
356+ 		logger :       newLogger (root , "" ),
357+ 		level :        level ,
358+ 		observedLogs : observedLogs ,
359+ 	})
360+ 	logger  :=  newLogger (root , "" )
361+ 	return  logger , nil 
362+ }
363+ 
259364func  createLogOutput (cfg  Config , enab  zapcore.LevelEnabler ) (zapcore.Core , error ) {
260365	switch  {
261366	case  cfg .toIODiscard :
@@ -282,6 +387,8 @@ func createLogOutput(cfg Config, enab zapcore.LevelEnabler) (zapcore.Core, error
282387
283388// DevelopmentSetup configures the logger in development mode at debug level. 
284389// By default the output goes to stderr. 
390+ // 
391+ // Deprecated: Prefer using localized loggers. Use logp.NewDevelopmentLogger. 
285392func  DevelopmentSetup (options  ... Option ) error  {
286393	cfg  :=  Config {
287394		Level :       DebugLevel ,
@@ -297,6 +404,8 @@ func DevelopmentSetup(options ...Option) error {
297404
298405// TestingSetup configures logging by calling DevelopmentSetup if and only if 
299406// verbose testing is enabled (as in 'go test -v'). 
407+ // 
408+ // Deprecated: Prefer using localized loggers. Use logp.NewTestingLogger. 
300409func  TestingSetup (options  ... Option ) error  {
301410	// Use the flag to avoid a dependency on the testing package. 
302411	f  :=  flag .Lookup ("test.v" )
0 commit comments