-
Notifications
You must be signed in to change notification settings - Fork 49
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
Document environment variables #120
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
<!---[![Coverage Status](https://coveralls.io/repos/github/ipfs/go-log/badge.svg?branch=master)](https://coveralls.io/github/ipfs/go-log?branch=master)---> | ||
|
||
[![](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 | ||
|
||
|
@@ -35,22 +29,91 @@ 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) | ||
``` | ||
|
||
or individually: | ||
|
||
```go | ||
lvl, err := logging.LevelFromString("error") | ||
if err != nil { | ||
panic(err) | ||
} | ||
if err != nil { | ||
panic(err) | ||
} | ||
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` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! This is pretty neat. |
||
|
||
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)! | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also add a note about regex: