Skip to content

streamingfast/logging

Repository files navigation

StreamingFast Logging library

reference License

This is the logging library used as part of StreamingFast.

Usage

In all library packages (by convention, use the import path):

var zlog *zap.Logger

func init() {
	logging.Register("github.com/path/to/my/package", &zlog)
}

In main packages:

var zlog *zap.Logger

func setupLogger() {
	logging.Register("main", &zlog)

	logging.Set(logging.MustCreateLogger())
	// Optionally set a different logger here and there,
	// using a regexp matching the registered names:
	//logging.Set(zap.NewNop(), "eosdb")
}

In tests (to avoid a race between the init() statements)

func init() {
	if os.Getenv("DEBUG") != "" {
		logging.Override(logging.MustCreateLoggerWithLevel("test", zap.NewAtomicLevelAt(zap.DebugLevel)), ""))
	}
}

You can switch log levels dynamically, by poking the port 1065 like this:

On listening servers (port 1065, hint: logs!)

  • curl http://localhost:1065/ -XPUT -d '{"level": "debug"}'

Zapx

We provide the package zapx as a way to add some helpers that are called mostly similar as regular zap named field like zap.String(<name>, <value>) to make some recurring use cases easier to implement globally.

  • zapx.Secret(<name>, <value>) print the string obfuscated using a 1/4 ratio for masking the input, see test cases to "see" how it looks like.

Contributing

Issues and PR in this repo related strictly to the streamingfast logging library.

Report any protocol-specific issues in their respective repositories

Please first refer to the general StreamingFast contribution guide, if you wish to contribute to this code base.

License

Apache 2.0