Ejemplo n.º 1
0
func SetDebug(d bool) {
	// sort of unnecessary but hey, standards
	lock.Lock()
	defer lock.Unlock()
	debug = d
	protolog.SetLogger(protolog.GlobalLogger().AtLevel(protolog.Level_LEVEL_DEBUG))
}
Ejemplo n.º 2
0
func register() {
	protolog.SetLogger(protolog.NewLogger(NewPusher(globalPusherOptions), globalLoggerOptions))
}
Ejemplo n.º 3
0
func register() {
	protolog.SetLogger(protolog.NewLogger(newPusher(globalMarshaller, globalLogDebug), globalLoggerOptions))
}
Ejemplo n.º 4
0
// SetupLogging sets up logging.
func SetupLogging(appName string, env Env) error {
	var pushers []protolog.Pusher
	if !env.DisableStderrLog {
		pushers = append(
			pushers,
			protolog.NewStandardWritePusher(
				protolog.NewFileFlusher(
					os.Stderr,
				),
			),
		)
	}
	if env.LogDir != "" {
		pushers = append(
			pushers,
			protolog.NewStandardWritePusher(
				protolog.NewWriterFlusher(
					&lumberjack.Logger{
						Filename:   filepath.Join(env.LogDir, fmt.Sprintf("%s.log", appName)),
						MaxBackups: 3,
					},
				),
			),
		)
	}
	if env.SyslogNetwork != "" && env.SyslogAddress != "" {
		writer, err := syslog.Dial(
			env.SyslogNetwork,
			env.SyslogAddress,
			syslog.LOG_INFO,
			appName,
		)
		if err != nil {
			return err
		}
		pushers = append(
			pushers,
			protosyslog.NewPusher(
				writer,
				protosyslog.PusherOptions{},
			),
		)
	}
	if len(pushers) > 0 {
		protolog.SetLogger(
			protolog.NewStandardLogger(
				protolog.NewMultiPusher(
					pushers...,
				),
			),
		)
	} else {
		protolog.SetLogger(
			protolog.DiscardLogger,
		)
	}
	protolog.RedirectStdLogger()
	if env.LogLevel != "" {
		levelValue, ok := protolog.Level_value[fmt.Sprintf("LEVEL_%s", strings.ToUpper(env.LogLevel))]
		if !ok {
			return fmt.Errorf("pkglog: unknown log level: %s", env.LogLevel)
		}
		protolog.SetLevel(protolog.Level(levelValue))
	}
	return nil
}