Yet another Go logging library for user-friendly applications, with colors!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
900 B

package log
import (
// An internal map of named loggers. This allows for GetLogger() to be called
// many times from anywhere in your code base, but for only one logger instance
// to be created for it.
var (
loggers map[string]*Logger
loggerMutex sync.Mutex
func init() {
loggers = map[string]*Logger{}
// Logger stores the configuration for a named logger instance.
type Logger struct {
Name string
Config *Config
// Private cached text/template, the first time the formatter is used.
template *template.Template
// GetLogger initializes and returns a new Logger.
func GetLogger(name string) *Logger {
defer loggerMutex.Unlock()
// Initialize the logger the first time we ask for it.
if _, ok := loggers[name]; !ok {
loggers[name] = &Logger{
Name: name,
Config: DefaultConfig(),
return loggers[name]