Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

algod: Write to stdout when config.LogSizeLimit is 0 or -o is passed to algod. #3903

Merged
merged 8 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/algod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ var versionCheck = flag.Bool("v", false, "Display and write current build versio
var branchCheck = flag.Bool("b", false, "Display the git branch behind the build")
var channelCheck = flag.Bool("c", false, "Display and release channel behind the build")
var initAndExit = flag.Bool("x", false, "Initialize the ledger and exit")
var logToStdout = flag.Bool("o", false, "Write to stdout instead of node.log by overriding config.LogSizeLimit to 0")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, but now I'm imagining the convention -o foo to log to file foo and -o - for stdout.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc would note "defaults to {data dir}/node.log"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not add that feature unless there's a real reason that it would be useful. I kinda want to remove most of these flags, not sure they're actually used anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess picking a different letter would address that concern but all the good letters are taken already.

var peerOverride = flag.String("p", "", "Override phonebook with peer ip:port (or semicolon separated list: ip:port;ip:port;ip:port...)")
var listenIP = flag.String("l", "", "Override config.EndpointAddress (REST listening address) with ip:port")
var sessionGUID = flag.String("s", "", "Telemetry Session GUID to use")
var telemetryOverride = flag.String("t", "", `Override telemetry setting if supported (Use "true", "false", "0" or "1"`)
var telemetryOverride = flag.String("t", "", `Override telemetry setting if supported (Use "true", "false", "0" or "1")`)
var seed = flag.String("seed", "", "input to math/rand.Seed()")

func main() {
Expand Down Expand Up @@ -292,6 +293,10 @@ func run() int {
}
}

if logToStdout != nil && *logToStdout {
cfg.LogSizeLimit = 0
}

err = s.Initialize(cfg, phonebookAddresses, string(genesisText))
if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down
2 changes: 1 addition & 1 deletion config/localTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type Local struct {
// SRV-based phonebook
DNSBootstrapID string `version[0]:"<network>.algorand.network"`

// Log file size limit in bytes
// Log file size limit in bytes. When set to 0 logs will be written to stdout.
LogSizeLimit uint64 `version[0]:"1073741824"`

// text/template for creating log archive filename.
Expand Down
9 changes: 8 additions & 1 deletion daemon/algod/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
Expand Down Expand Up @@ -82,7 +83,13 @@ func (s *Server) Initialize(cfg config.Local, phonebookAddresses []string, genes
maxLogAge = 0
}
}
logWriter := logging.MakeCyclicFileWriter(liveLog, archive, cfg.LogSizeLimit, maxLogAge)

var logWriter io.Writer
if cfg.LogSizeLimit > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if args.logToStdout || cfg.LogSizeLimit <= 0 { ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main function overrides cfg.LogSizeLimit, so this is still the right condition.

logWriter = logging.MakeCyclicFileWriter(liveLog, archive, cfg.LogSizeLimit, maxLogAge)
} else {
logWriter = os.Stdout
}
s.log.SetOutput(logWriter)
s.log.SetJSONFormatter()
s.log.SetLevel(logging.Level(cfg.BaseLoggerDebugLevel))
Expand Down