-
Notifications
You must be signed in to change notification settings - Fork 5
Environments
Michael Kenney edited this page Jan 23, 2019
·
2 revisions
bdlm/log has no notion of environment.
If you wish for hooks and formatters to only be used in specific environments, you should handle that yourself. For example, if your application has a global variable Environment, which is a string representation of the environment you could do:
import (
log "github.com/bdlm/log"
)
init() {
// Do something here to set environment depending on an environment variable
// or command-line flag
if Environment == "production" {
log.SetFormatter(&log.JSONFormatter{})
} else {
// The TextFormatter is the default, you don't actually have to do this.
log.SetFormatter(&log.TextFormatter{})
}
}This configuration is how bdlm/log was intended to be used, but JSON in production is mostly only useful if you do log aggregation with tools like Splunk or Logstash.
Which one will reach the other side of the river: The one who dreams of a raft, or the one that hitchhikes to the next bridge?