modulepackage
0.0.0-20230608130331-f22c91403091
Repository: https://github.com/streamingfast/logging.git
Documentation: pkg.go.dev
# README
StreamingFast Logging library
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"}'
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
# Packages
No description provided by the author
# Functions
ApplicationLogger calls `RootLogger` followed by `InstantiateLoggers`.
Deprecated: Will be removed in a future version, use `InstantiateLoggers` and configure it the way you want instead.
CreateLogger can be used to create the correct zap logger based on the environment.
CreateLoggerWithLevel behaves exactly like `CreateLogger`, but you can pass the atomic level that should be used for the logger that will use this atomic level.
Debug is a shortcut for `Logger(ctx, zlog).Debug("some message", ...some fields)`.
Error is a shortcut for `Logger(ctx, zlog).Error("some message", ...some fields)`.
Extend is different than `Set` by being able to re-configure the existing logger set for all registered logger in the registry.
FlagFields returns all flag as `zap.Field` element for easy logging.
Info is a shortcut for `Logger(ctx, zlog).Info("some message", ...some fields)`.
InstantiateLoggers correctly instantiate all the loggers of your application at the correct level based on various source of information.
No description provided by the author
IsTraceEnabled receives the a short name value (usually the app name) and the fully qualified package identifier (i.e.
No description provided by the author
Logger is used to retrieved the logger from the context.
LoggerDefaultLevel can be used to set the default level of the logger if nothing else is overriding it.
LoggerOnUpdate enable you to have a hook function that will receive the new logger that is going to be assigned to your logger instance.
Deprecated: You should use MustCreateLoggerWithServiceName.
MustCreateLoggerWithLevel behaves exactly like `MustCreateLogger`, but you can pass the atomic level that should be used for the logger that will use this atomic level.
MustCreateLogger has the same behavior as `CreateLogger` function.
No description provided by the author
No description provided by the author
No description provided by the author
Override sets the given logger on previously registered and next registrations.
PackageLogger creates a new no-op logger (via `zap.NewNop`) and automatically registered it withing the logging registry with a tracer that can be be used for conditionally tracing code.
Deprecated: Use `var zlog, _ = logging.PackageLogger(<shortName>, "...")` instead.
Deprecated: Use LoggerOnUpdate instead.
RootLogger should be used to get a logger for a top-level binary application which will immediately activate all registered loggers with a logger.
No description provided by the author
TestingOverride calls `Override` (or `Set`, see below) with a development logger setup correctly with the right level based on some environment variables.
Warn is a shortcut for `Logger(ctx, zlog).Warn("some message", ...some fields)`.
WithConsoleToStderr configures the console to log to `stderr`, which is the default.
WithConsoleToStdout configures the console to log to `stdout` instead of the default which is to log to `stderr`.
WithDefaultLevel is going to set `level` as the default level for all loggers instantiated.
WithDefaultSpec is going to set `level` of the loggers affected by the spec, each entry being of the form `<matcher>=<level>` where the `matcher` is the matching input (can be a short name directly or a regex matched against short name and package ID second).
WithLevel returns a zap WrapCore option that change the underlying level.
WithLogger is used to create a new context with a logger added to it so it can be later retrieved using `Logger`.
WithLogLevelSwitcherServerAutoStart is going to start the HTTP server that enables switching log levels dynamically based on a key without relying on the built-in production environment detector to determine if in production and only then starting the HTTP server.
WithLogLevelSwitcherServerListeningAddress configures the listening address the HTTP server log level switcher listens to if started.
WithOutputToFile configures the loggers to write to the `logFile` received in the argument in **addition** to the console logging that is performed automatically.
WithProductionDetector changes the production environment detector to the one provided as argument.
The actual production logger is automatically inferred based on various environmental conditions, defaulting to `stackdriver` format which is ultimately just a JSON logger with formatted in such that is ingestible by Stackdriver compatible ingestor(s) (todays know as Google Cloud Operations).
No description provided by the author
Deprecated: Will be removed in a future version, if your were using that in `ApplicationLogger`, use `RootLogger` and set the option there then in a `init` func in your main entry point, call `InstantiateLoggers`.
Deprecated: Use `WithLogLevelSwitcherServerAutoStart` instead.
Deprecated: Use `WithLogLevelSwitcherServerListeningAddress` instead.
# Variables
No description provided by the author
# Interfaces
No description provided by the author
LoggerOption are option parameters that you can set when creating a `PackageLogger`.
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author