コード例 #1
0
ファイル: logging.go プロジェクト: jawher/admin
// Initialize logging from command arguments.
func initLogging(configFile string) {
	var err error
	log.RegisterReceiver("stderr", &CustomReceiver{})
	if configFile == "" {
		logger, err = log.LoggerFromConfigAsString(defaultLoggingConfig)
		checkLogFatal("Failed to load default logging configuration: %s", err)
	} else {
		logger, err = log.LoggerFromConfigAsFile(configFile)
		checkLogFatal("Failed to initialize custom logging file %s: %s", configFile, err)
	}
}
コード例 #2
0
ファイル: suite.go プロジェクト: choirudin2210/platform-layer
// InstallTestLogger will install a logger with appropriate configuration for the current testing setup. It returns a
// the logger that was overwritten; this should be restored (via a call to RestoreLogger) at the conclusion of the test.
func InstallTestLoggerWithLogLevel(t testing.TB, logLevel string) log.LoggerInterface {
	golog.SetOutput(ioutil.Discard)

	loggerIdNum++
	loggerId := fmt.Sprintf("testLogger%d", loggerIdNum)

	log.RegisterReceiver(loggerId, &testLogger{tb: t})

	config := fmt.Sprintf(testLoggerConfigTemplate, logLevel, loggerId)
	if logger, err := log.LoggerFromConfigAsString(config); err != nil {
		panic(err)
	} else {
		stashed := log.Current
		log.ReplaceLogger(logger)
		return stashed
	}
}