https://github.com/followtheprocess/log
Simple, fast, opinionated logging for command line applications in Go
https://github.com/followtheprocess/log
go logging
Last synced: 2 months ago
JSON representation
Simple, fast, opinionated logging for command line applications in Go
- Host: GitHub
- URL: https://github.com/followtheprocess/log
- Owner: FollowTheProcess
- License: mit
- Created: 2025-03-30T14:44:08.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-04-10T14:08:33.000Z (3 months ago)
- Last Synced: 2025-04-10T15:49:59.531Z (3 months ago)
- Topics: go, logging
- Language: Go
- Homepage:
- Size: 587 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# log
[](https://github.com/FollowTheProcess/log)
[](https://pkg.go.dev/github.com/FollowTheProcess/log)
[](https://goreportcard.com/report/github.com/FollowTheProcess/log)
[](https://github.com/FollowTheProcess/log)
[](https://github.com/FollowTheProcess/log/actions?query=workflow%3ACI)
[](https://codecov.io/gh/FollowTheProcess/log)Simple, fast, opinionated logging for command line applications 🪵
![]()
## Project Description
`log` is a tiny and incredibly simple logging library designed to output nicely presented, human readable, levelled log messages. Ideal for command line applications ✨
There are many great logging libraries for Go out there, but so many of them are IMO too flexible and too complicated. I wanted a small, minimal dependency, opinionated logger I could
use everywhere across all my Go projects (which are mostly command line applications). So I made one 🚀## Installation
```shell
go get github.com/FollowTheProcess/log@latest
```## Quickstart
```go
package mainimport (
"fmt"
"os""github.com/FollowTheProcess/log"
)func main() {
logger := log.New(os.Stderr)logger.Debug("Debug me") // By default this one won't show up, default log level is INFO
logger.Info("Some information here", "really", true)
logger.Warn("Uh oh!")
logger.Error("Goodbye")
}
```## Usage Guide
Make a new logger
```go
logger := log.New(os.Stderr)
```### Levels
`log` provides a levelled logger with the normal levels you'd expect:
```go
log.LevelDebug
log.LevelInfo
log.LevelWarn
log.LevelError
```You write log lines at these levels with the corresponding methods on the `Logger`:
```go
logger.Debug("...") // log.LevelDebug
logger.Info("...") // log.LevelInfo
logger.Warn("...") // log.LevelWarn
logger.Error("...") // log.LevelError
```And you can configure a `Logger` to display logs at or higher than a particular level with the `WithLevel` option...
```go
logger := log.New(os.Stderr, log.WithLevel(log.LevelDebug))
```### Key Value Pairs
`log` provides "semi structured" logs in that the message is free form text but you can attach arbitrary key value pairs to any of the log methods
```go
logger.Info("Doing something", "cache", true, "duration", 30 * time.Second, "number", 42)
```You can also create a "sub logger" with persistent key value pairs applied to every message
```go
sub := logger.With("sub", true)sub.Info("Hello from the sub logger", "subkey", "yes") // They can have their own per-method keys too!
```
![]()
### Prefixes
`log` lets you apply a "prefix" to your logger, either as an option to `log.New` or by creating a "sub logger" with that prefix!
```go
logger := log.New(os.Stderr, log.Prefix("http"))
```Or...
```go
logger := log.New(os.Stderr)
prefixed := logger.Prefixed("http")
```
![]()