Skip to content

Commit

Permalink
add console log flag
Browse files Browse the repository at this point in the history
  • Loading branch information
hubchub committed Jun 28, 2023
1 parent 980479a commit af16550
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
6 changes: 6 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ var (
Usage: "Enable colorized logging",
}


LogToStdOutFlag = cli.BoolFlag{
Name: "logtostdout",
Usage: "Write log messages to stdout",
}

// 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
2 changes: 1 addition & 1 deletion helm/templates/_statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- image: {{ .Values.goQuai.image.name -}}:{{- .Values.goQuai.image.version }}
imagePullPolicy: Always
name: prime-go-quai
command: ["./build/bin/go-quai", --$(NETWORK), "--verbosity", $(VERBOSITY), "--slices", $(SLICES), "--syncmode", "full", "--http", "--http.vhosts=*", "--ws", <MINER_ETHERBASE>, "--http.addr", "0.0.0.0", "--http.api", "eth,net,web3,quai,txpool,debug", "--ws.addr", "0.0.0.0", "--ws.api", "eth,net,web3,quai,txpool,debug", "--port", $(TCP_PORT), "--http.port", $(HTTP_PORT), "--ws.port", $(WS_PORT), "--ws.origins=*", "--http.corsdomain=*", "--gcmode", "archive", "--nonce", $(NONCE), <REGION>, <ZONE>, <SUB>, <DOM>]
command: ["./build/bin/go-quai", --$(NETWORK), "--logtostdout", "--verbosity", $(VERBOSITY), "--slices", $(SLICES), "--syncmode", "full", "--http", "--http.vhosts=*", "--ws", <MINER_ETHERBASE>, "--http.addr", "0.0.0.0", "--http.api", "eth,net,web3,quai,txpool,debug", "--ws.addr", "0.0.0.0", "--ws.api", "eth,net,web3,quai,txpool,debug", "--port", $(TCP_PORT), "--http.port", $(HTTP_PORT), "--ws.port", $(WS_PORT), "--ws.origins=*", "--http.corsdomain=*", "--gcmode", "archive", "--nonce", $(NONCE), <REGION>, <ZONE>, <SUB>, <DOM>]
env:
- name: COINBASE_ADDR
valueFrom:
Expand Down
28 changes: 18 additions & 10 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package log

import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
Expand All @@ -25,6 +26,8 @@ func ConfigureLogger(ctx *cli.Context) {
logLevel := logrus.Level(ctx.GlobalInt("verbosity"))
Log.SetLevel(logLevel)

logToStdOut := ctx.GlobalBool("logtostdout")

log_filename := "nodelogs"
regionNum := ctx.GlobalString("region")

Expand All @@ -45,12 +48,16 @@ func ConfigureLogger(ctx *cli.Context) {
TimestampFormat: "01-02|15:04:05.000",
}

Log.SetOutput(&lumberjack.Logger{
Filename: log_filename,
MaxSize: 500, // megabytes
MaxBackups: 5,
MaxAge: 28, //days
})
if logToStdOut {
Log.SetOutput(os.Stdout)
} else {
Log.SetOutput(&lumberjack.Logger{
Filename: log_filename,
MaxSize: 500, // megabytes
MaxBackups: 5,
MaxAge: 28, //days
})
}
}

func SetLevelInt(level int) {
Expand Down Expand Up @@ -81,6 +88,7 @@ func New(out_path string) Logger {
func Trace(msg string, args ...interface{}) {
Log.Trace(constructLogMessage(msg, args...))
}

// Individual logging instances will use the following method.
func (l Logger) Trace(msg string, args ...interface{}) {
l.Logger.Trace(constructLogMessage(msg, args...))
Expand All @@ -90,7 +98,7 @@ func Debug(msg string, args ...interface{}) {
Log.Debug(constructLogMessage(msg, args...))
}
func (l Logger) Debug(msg string, args ...interface{}) {
l.Logger.Debug(constructLogMessage(msg, args...))
l.Logger.Debug(constructLogMessage(msg, args...))
}

func Info(msg string, args ...interface{}) {
Expand Down Expand Up @@ -174,19 +182,19 @@ func constructLogMessage(msg string, fields ...interface{}) string {
lineInfo := reportLineNumber(2)

if len(fields) != 1 {
// Sometimes we want to log a single string,
// Sometimes we want to log a single string,
if len(fields)%2 != 0 {
fields = append(fields, "MISSING VALUE")
}

for i := 0; i < len(fields); i += 2 {
key := fields[i]
value := fields[i+1]
pairs = append(pairs, fmt.Sprintf("%v=%v", key, value))
}
}

if lineInfo != ""{
if lineInfo != "" {
return fmt.Sprintf("%-40s %-40s %s", lineInfo, msg, strings.Join(pairs, " "))
} else {
return fmt.Sprintf("%-40s %s", msg, strings.Join(pairs, " "))
Expand Down

0 comments on commit af16550

Please sign in to comment.