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

Logging in JSON format #21926

Closed
willianpaixao opened this issue Nov 30, 2020 · 5 comments · Fixed by #22207
Closed

Logging in JSON format #21926

willianpaixao opened this issue Nov 30, 2020 · 5 comments · Fixed by #22207
Assignees

Comments

@willianpaixao
Copy link
Contributor

Rationale

There should be more options on logging format for Geth.
At the moment, the only option available is the verbosity level.
For example, logging parsing is a great tool for managing highly available nodes.
I am suggesting two flags, one that would change the formatted log to JSON and a second flag to specify the output log file, rather than dump onto stdout.

These two flags combined would allow a variety of tools to monitor the health of a Geth node.

Implementation

The log/ folder, containing the log15 package already parses the log messages in JSON format, but it converts to syslog before dumping. The first mentioned flag would skip the conversation.

Also, it's (to my knowledge) trivial to create a flag that receives one argument (file) and writes the log into it rather than stdout.

@rjl493456442
Copy link
Member

Regarding the file output, you can easily rediect the output. Actually in a very old version Geth, it's supported to dump the log to files. While we think it's totally unecessary.

@mjpowersjr
Copy link

Just a few weeks ago I started to look at patching a local build of geth to support this. This seems like a great feature. :-)

@willianpaixao
Copy link
Contributor Author

Hi @rjl493456442, I currently use redirectors to save the log into a file.
Although the vast majority of the services out there have this feature (specify output log file).

But the JSON format logging could it's a good candidate for a feature.

@MysticRyuujin
Copy link
Contributor

Not to mention that support for log redirection stuff is terrible in Windows, and when used with something like systemd and journalctl - breaking out stderr and stdout is harder to do, and if you want to syslog stuff it's also hard to get levels correct.

There's multiple instances of people patching geth themselves to support log files because of the assumption that redirecting output is good enough 🙁

@holiman
Copy link
Contributor

holiman commented Jan 21, 2021

This is what clef uses (auditlog.go):


func NewAuditLogger(path string, api ExternalAPI) (*AuditLogger, error) {
	l := log.New("api", "signer")
	handler, err := log.FileHandler(path, log.LogfmtFormat())
	if err != nil {
		return nil, err
	}
	l.SetHandler(handler)
	l.Info("Configured", "audit log", path)
	return &AuditLogger{l, api}, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants