Skip to content

Commit

Permalink
Add showcolors flag to enable/disable colored log prints for non-TTYs
Browse files Browse the repository at this point in the history
  • Loading branch information
Djadih committed May 23, 2023
1 parent 72116c0 commit 8b05fff
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ ifeq ($(QUAI_STATS),true)
BASE_CMD += --quaistats ${STATS_NAME}:${STATS_PASS}@${STATS_HOST}
endif

ifeq ($(SHOW_COLORS),true)
BASE_CMD += --showcolors
endif

# Build suburl strings for slice specific subclient groups
# WARNING: Only connect to dom/sub clients over a trusted network.
ifeq ($(REGION),2)
Expand Down
1 change: 1 addition & 0 deletions cmd/go-quai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ var (
utils.GpoPercentileFlag,
utils.GpoMaxGasPriceFlag,
utils.GpoIgnoreGasPriceFlag,
utils.ShowColorsFlag,
configFileFlag,
utils.RegionFlag,
utils.ZoneFlag,
Expand Down
7 changes: 7 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,13 @@ var (
Usage: "Password to authorize access to the database",
Value: metrics.DefaultConfig.InfluxDBPassword,
}

// Output flags
ShowColorsFlag = cli.BoolFlag{
Name: "showcolors",
Usage: "Enable colorized logging",
}

// Tags are part of every measurement sent to InfluxDB. Queries on tags are faster in InfluxDB.
// For example `host` tag could be used so that we can group all nodes and average a measurement
// across all of them, but also so that we can select a specific node and inspect its measurements.
Expand Down
20 changes: 11 additions & 9 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ type Logger = *logrus.Logger
var Log Logger = logrus.New()

func init() {
Log.Formatter = &logrus.TextFormatter{
ForceColors: true,
PadLevelText: true,
FullTimestamp: true,
TimestampFormat: "01-02|15:04:05",
CallerPrettyfier: callerPrettyfier,
}

}

func ConfigureLogger(ctx *cli.Context) {
Expand All @@ -39,14 +33,22 @@ func ConfigureLogger(ctx *cli.Context) {

if ctx.GlobalIsSet("zone") {
zoneNum := ctx.GlobalString("zone")
log_filename = filepath.Join(log_filename, "zone-" + regionNum + "-" + zoneNum)
log_filename = filepath.Join(log_filename, "zone-"+regionNum+"-"+zoneNum)
} else if ctx.GlobalIsSet("region") {
log_filename = filepath.Join(log_filename, "region-" + regionNum)
log_filename = filepath.Join(log_filename, "region-"+regionNum)
} else {
log_filename = filepath.Join(log_filename, "prime")
}
log_filename += ".log"

Log.Formatter = &logrus.TextFormatter{
ForceColors: ctx.GlobalBool("showcolors"),
PadLevelText: true,
FullTimestamp: true,
TimestampFormat: "01-02|15:04:05",
CallerPrettyfier: callerPrettyfier,
}

Log.SetOutput(&lumberjack.Logger{
Filename: log_filename,
MaxSize: 5, // megabytes
Expand Down
3 changes: 3 additions & 0 deletions network.env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ STATS_NAME=
STATS_PASS=
STATS_HOST=
ENABLE_PPROF=false

# Output format variables
SHOW_COLORS=true

0 comments on commit 8b05fff

Please sign in to comment.