Beispiel #1
0
func (log *Standard) Configure(style string, debug bool, filename string) {
	log.configureMutex.Lock()
	defer log.configureMutex.Unlock()

	log.filename = filename

	var logfmt string
	if debug {
		logfmt = fancyFormat
	} else {
		logfmt = defaultFormat
	}

	// Override the format above if an explicit style was specified.
	switch style {
	case "default":
		logfmt = defaultFormat // Default
	case "plain":
		logfmt = plainFormat // Plain
	case "file":
		logfmt = fileFormat // Good for logging to files
	case "fancy":
		logfmt = fancyFormat // Fancy, good for terminals with color
	}

	if debug {
		logging.SetLevel(logging.DEBUG, log.module)
	}

	logging.SetFormatter(logging.MustStringFormatter(logfmt))
}
Beispiel #2
0
func (log *Standard) setLogLevelInfo() {
	initLoggingSetLevelMutex.Lock()
	defer initLoggingSetLevelMutex.Unlock()

	if _, found := initLoggingSetLevelCalled[log.module]; !found {
		logging.SetLevel(logging.INFO, log.module)
		initLoggingSetLevelCalled[log.module] = struct{}{}
	}
}
Beispiel #3
0
func (log *Standard) initLogging() {
	// Logging is always done to stderr. It's the responsibility of the
	// launcher (like launchd on OSX, or the autoforking code) to set up stderr
	// to point to the appropriate log file.
	initLoggingBackendOnce.Do(func() {
		logBackend := logging.NewLogBackend(os.Stderr, "", 0)
		logging.SetBackend(logBackend)
		logging.SetLevel(logging.INFO, log.module)
	})
}
Beispiel #4
0
func (log *Standard) initLogging(iow io.Writer) {
	// Logging is always done to the given io.Writer. It's the
	// responsibility of the launcher (like launchd on OSX, or the
	// autoforking code) to set it up to point to the appropriate
	// log file.
	initLoggingBackendOnce.Do(func() {
		logBackend := logging.NewLogBackend(iow, "", 0)
		logging.SetBackend(logBackend)
	})

	initLoggingSetLevelMutex.Lock()
	defer initLoggingSetLevelMutex.Unlock()
	if initLoggingSetLevelCalled == nil {
		initLoggingSetLevelCalled = make(map[string]bool)
	}
	if !initLoggingSetLevelCalled[log.module] {
		logging.SetLevel(logging.INFO, log.module)
		initLoggingSetLevelCalled[log.module] = true
	}
}