From 07289bfbc17bcf449e7a1a6479c4acad17ce3e37 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 19 Aug 2021 11:42:29 -0700 Subject: [PATCH 1/4] doc: fix readme badges --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4a9587c..049e17f 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,8 @@ # go-log -[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) -[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) -[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) -[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) -[![GoDoc](https://godoc.org/github.com/ipfs/go-log?status.svg)](https://godoc.org/github.com/ipfs/go-log) -[![CircleCI](https://img.shields.io/circleci/build/github/ipfs/go-log?style=flat-square)](https://circleci.com/gh/ipfs/go-log) - - - +[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](https://protocol.ai) +[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.io/) +[![GoDoc](https://pkg.go.dev/badge/github.com/ipfs/go-log/v2.svg)](https://pkg.go.dev/github.com/ipfs/go-log/v2) > The logging library used by go-ipfs From 42f933f3c40fc5333479639cf0a99b802b3237b0 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 19 Aug 2021 11:42:52 -0700 Subject: [PATCH 2/4] doc: fix example indentation --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 049e17f..a0cae1b 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,9 @@ Levels may be set for all loggers: ```go lvl, err := logging.LevelFromString("error") - if err != nil { - panic(err) - } +if err != nil { + panic(err) +} logging.SetAllLoggers(lvl) ``` @@ -39,9 +39,9 @@ or individually: ```go lvl, err := logging.LevelFromString("error") - if err != nil { - panic(err) - } +if err != nil { + panic(err) +} logging.SetLogLevel("foo", "info") ``` From c0bf4db2e1ca48343e3e453e28e00738cf4715ea Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 19 Aug 2021 11:43:00 -0700 Subject: [PATCH 3/4] doc: document environment variables --- README.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/README.md b/README.md index a0cae1b..89c82c2 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,75 @@ if err != nil { logging.SetLogLevel("foo", "info") ``` +### Environment Variables + +This package can be configured through various environment variables. + +#### `GOLOG_LOG_LEVEL` + +Specifies the log-level, both globally and on a per-subsystem basis. + +For example, the following will set the global minimum log level to `error`, but reduce the minimum +log level for `subsystem1` to `info` and reduce the minimum log level for `subsystem2` to debug. + +```bash +export GOLOG_LOG_LEVEL="error,subsystem1=info,subsystem2=debug" +``` + +`IPFS_LOGGING` is a deprecated alias for this environment variable. + +#### `GOLOG_FILE` + +Specifies that logs should be written to the specified file. If this option is _not_ specified, logs are written to standard error. + +```bash +export GOLOG_FILE="/path/to/my/file.log" +``` + +#### `GOLOG_OUTPUT` + +Specifies where logging output should be written. Can take one or more of the following values, combined with `+`: + +- `stdout` -- write logs to standard out. +- `stderr` -- write logs to standard error. +- `file` -- write logs to the file specified by `GOLOG_FILE` + +For example, if you want to log to both a file and standard error: + +```bash +export GOLOG_FILE="/path/to/my/file.log" +export GOLOG_OUTPUT="stderr+file" +``` + +Setting _only_ `GOLOG_FILE` will prevent logs from being written to standard error. + +#### `GOLOG_LOG_FMT` + +Specifies the log message format. It supports the following values: + +- `color` -- human readable, colorized (ANSI) output +- `nocolor` -- human readable, plain-text output. +- `json` -- structured JSON. + +For example, to log structured JSON (for easier parsing): + +```bash +export GOLOG_LOG_FMT="json" +``` + +The logging format defaults to `color` when the output is a terminal, and `nocolor` otherwise. + +`IPFS_LOGGING_FMT` is a deprecated alias for this environment variable. + +#### `GOLOG_LOG_LABELS` + +Specifies a set of labels that should be added to all log messages as comma-separated key-value +pairs. For example, the following add `{"app": "example_app", "dc": "sjc-1"}` to every log entry. + +```bash +export GOLOG_LOG_LABELS="app=example_app,dc=sjc-1" +``` + ## Contribute Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/go-log/issues)! From 205c48c19ba6fe04159232f1bbe87a5a89b746e8 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 19 Aug 2021 12:44:29 -0700 Subject: [PATCH 4/4] doc: document setting log level by regular expression --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 89c82c2..c996715 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,19 @@ logging.SetAllLoggers(lvl) or individually: ```go -lvl, err := logging.LevelFromString("error") +err := logging.SetLogLevel("net:pubsub", "info") +if err != nil { + panic(err) +} +``` + +or by regular expression: + +```go +err := logging.SetLogLevelRegex("net:.*", "info") if err != nil { panic(err) } -logging.SetLogLevel("foo", "info") ``` ### Environment Variables