multilog

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2023 License: MIT Imports: 9 Imported by: 0

README

Multilog

Multilog combines a set of logger instances for each log level. The log messages are output to several targets. Each target logger can write to a different output stream, use its own log format and be a different log library. Each log level can have its own set of loggers.

This can for example be used to log warnings and error messages to stdout in a usual format as a microservice inside a container, as it is defined in the 12 factor rules. At the same time the activities of the microservice could be logged in a JSON format at log level info, warning and error to a file inside the container's file system. The file could be watched for example by an Grafana agent in a sidecar to forward the log messages to Grafana Loki used by the application management desk.

The multilog library supports currently zerolog as basic logger. Most methods for logging with zerolog are supported. The basic usage is

mlog := logger.ZeroLog{}

// add console logger
console := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}).
	With().
	Timestamp().
	Logger()
mlog.AddLoggerWarn(&console)

mlog.Warn().Msg("its a warning")

See the full running example in main.go

Deployment

The example app in main.go logs to the console and a file. The log file will be rotated every hour and stored for 24 hours in the example. The settings can be configured in .env as shown in .env_example. Local testing can be done with .env configured using the Justfile to run the demo and a local promtail in two terminal windows:

just serve

just promtail

Usually, you will deploy your app in the cloud. An example for the Dockerfile is given. Further, an example how to deploy your app together with a promtail sidecar is shown in deploy. The sidecar will forward the content of the logfile shared by a volume to a Grafana Loki server. Create a sealed secret to access your GitLab registry and store it with the source for example:

kubectl create secret docker-registry multilog-registry --dry-run=client --docker-server=dockerhub.fokus.fraunhofer.de:5000 --docker-username=<Gitlab-Username> --docker-password=<Gitlab-Password> --docker-email=info@multilog.org -o json | kubeseal --scope cluster-wide -o yaml > multilog-registry.yaml

or create the secret directly for example:

kubectl create secret docker-registry multilog-registry --docker-server=dockerhub.fokus.fraunhofer.de:5000 --docker-username=<Gitlab-Username> --docker-password=<Gitlab-Password> --docker-email=info@multilog.org

Create a secret for promtail with the host part of the Grafana Loki server or the Grafana Cloud:

kubectl create secret generic promtail --from-literal=host='<host>'

The license agreement see here.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL