Skip to content

Commit

Permalink
[FAB-5800] Allow orderer to set LogFormat backport
Browse files Browse the repository at this point in the history
The orderer's logs always print using the default format string which
includes colors in the output.  Although helpful when looking at a
console, this makes logs difficult to handle programatically.

This CR adds a LogFormat option to orderer.yaml and uses it to
initialize the logging format for the orderer.

Change-Id: I7c595aa42e34255114953fab3dcbeafffc5cd377
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Oct 2, 2017
1 parent 8d07299 commit 44fcb61
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions orderer/localconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type General struct {
GenesisFile string
Profile Profile
LogLevel string
LogFormat string
LocalMSPDir string
LocalMSPID string
BCCSP *bccsp.FactoryOpts
Expand Down Expand Up @@ -173,6 +174,7 @@ var defaults = TopLevel{
Address: "0.0.0.0:6060",
},
LogLevel: "INFO",
LogFormat: "%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}",
LocalMSPDir: "msp",
LocalMSPID: "DEFAULT",
BCCSP: bccsp.GetDefaultOpts(),
Expand Down Expand Up @@ -269,6 +271,9 @@ func (c *TopLevel) completeInitialization(configDir string) {
case c.General.LogLevel == "":
logger.Infof("General.LogLevel unset, setting to %s", defaults.General.LogLevel)
c.General.LogLevel = defaults.General.LogLevel
case c.General.LogFormat == "":
logger.Infof("General.LogFormat unset, setting to %s", defaults.General.LogFormat)
c.General.LogFormat = defaults.General.LogFormat

case c.General.GenesisMethod == "":
c.General.GenesisMethod = defaults.General.GenesisMethod
Expand Down
1 change: 1 addition & 0 deletions orderer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func main() {

// Set the logging level
func initializeLoggingLevel(conf *config.TopLevel) {
flogging.InitBackend(flogging.SetFormat(conf.General.LogFormat), os.Stderr)
flogging.InitFromSpec(conf.General.LogLevel)
if conf.Kafka.Verbose {
sarama.Logger = log.New(os.Stdout, "[sarama] ", log.Ldate|log.Lmicroseconds|log.Lshortfile)
Expand Down
3 changes: 3 additions & 0 deletions sampleconfig/orderer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ General:
# per: fabric/docs/Setup/logging-control.md
LogLevel: info

# Log Format: The format string to use when logging. Especially useful to disable color logging
LogFormat: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'

# Genesis method: The method by which the genesis block for the orderer
# system channel is specified. Available options are "provisional", "file":
# - provisional: Utilizes a genesis profile, specified by GenesisProfile,
Expand Down

0 comments on commit 44fcb61

Please sign in to comment.