Skip to content

Commit 44fcb61

Browse files
author
Jason Yellick
committed
[FAB-5800] Allow orderer to set LogFormat backport
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 <[email protected]>
1 parent 8d07299 commit 44fcb61

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

orderer/localconfig/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type General struct {
7777
GenesisFile string
7878
Profile Profile
7979
LogLevel string
80+
LogFormat string
8081
LocalMSPDir string
8182
LocalMSPID string
8283
BCCSP *bccsp.FactoryOpts
@@ -173,6 +174,7 @@ var defaults = TopLevel{
173174
Address: "0.0.0.0:6060",
174175
},
175176
LogLevel: "INFO",
177+
LogFormat: "%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}",
176178
LocalMSPDir: "msp",
177179
LocalMSPID: "DEFAULT",
178180
BCCSP: bccsp.GetDefaultOpts(),
@@ -269,6 +271,9 @@ func (c *TopLevel) completeInitialization(configDir string) {
269271
case c.General.LogLevel == "":
270272
logger.Infof("General.LogLevel unset, setting to %s", defaults.General.LogLevel)
271273
c.General.LogLevel = defaults.General.LogLevel
274+
case c.General.LogFormat == "":
275+
logger.Infof("General.LogFormat unset, setting to %s", defaults.General.LogFormat)
276+
c.General.LogFormat = defaults.General.LogFormat
272277

273278
case c.General.GenesisMethod == "":
274279
c.General.GenesisMethod = defaults.General.GenesisMethod

orderer/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func main() {
8686

8787
// Set the logging level
8888
func initializeLoggingLevel(conf *config.TopLevel) {
89+
flogging.InitBackend(flogging.SetFormat(conf.General.LogFormat), os.Stderr)
8990
flogging.InitFromSpec(conf.General.LogLevel)
9091
if conf.Kafka.Verbose {
9192
sarama.Logger = log.New(os.Stdout, "[sarama] ", log.Ldate|log.Lmicroseconds|log.Lshortfile)

sampleconfig/orderer.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ General:
4141
# per: fabric/docs/Setup/logging-control.md
4242
LogLevel: info
4343

44+
# Log Format: The format string to use when logging. Especially useful to disable color logging
45+
LogFormat: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'
46+
4447
# Genesis method: The method by which the genesis block for the orderer
4548
# system channel is specified. Available options are "provisional", "file":
4649
# - provisional: Utilizes a genesis profile, specified by GenesisProfile,

0 commit comments

Comments
 (0)