https://github.com/vncntx/captainslog
A simple but powerful logging library for Go
https://github.com/vncntx/captainslog
golang logging structured-logging
Last synced: 4 months ago
JSON representation
A simple but powerful logging library for Go
- Host: GitHub
- URL: https://github.com/vncntx/captainslog
- Owner: vncntx
- License: mit
- Created: 2018-08-05T14:07:43.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-02-25T09:48:22.000Z (over 3 years ago)
- Last Synced: 2025-08-15T05:25:33.436Z (11 months ago)
- Topics: golang, logging, structured-logging
- Language: Go
- Homepage: https://vincent.click/captainslog
- Size: 1.01 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: license
Awesome Lists containing this project
README

# captainslog
[](https://github.com/vncntx/captainslog/actions?query=workflow%3A%22Unit+Tests%22)
[](https://github.com/vncntx/captainslog/actions?query=workflow%3A%22Style+Checks%22)
[](https://pkg.go.dev/vincent.click/pkg/captainslog/v2?tab=doc)
[](https://conventionalcommits.org)
[](./license)
A simple logging library for [Go](https://golang.org/)
- cross-platform colors
- multiple log levels
- structured logging
- caller detection

## Installation
```
go get vincent.click/pkg/captainslog/v2
```
## Usage
This library is designed to provide a familiar yet powerful logging interface. Each log method accepts a format string and arguments. Structured logging is supported right out of the box. You can turn colors on/off, specify a custom datetime format, set the minimum level that will be logged, and even provide your own function to control how logs are written.
```go
package main
import (
"vincent.click/pkg/captainslog/v2"
)
var log = captainslog.NewLogger()
func main() {
log.Trace("this is %s", "captainslog")
log.Debug("this is %s", "captainslog")
log.Info("this is %s", "captainslog")
log.Warn("this is %s", "captainslog")
log.Error("this is %s", "captainslog")
log.Fields(
log.I("captain", "picard"),
log.I("first officer", "riker"),
log.I("science officer", "data"),
log.I("medical officer", "crusher"),
log.I("chief engineer", "la forge"),
log.I("security officer", "worf"),
).Info("starship enterprise")
}
```
## Format
There are several [log formats](./docs/format.md) included that you can choose from. It's also easy to write your own custom function to print logs just the way you want to.
## Performance
The main goals of this library are convenience and familiarity for programmers, but it should have reasonable performance for most projects. To see for yourself, run the benchmarks using `./tools benchmark`.
## Development
Please read the [Contribution Guide](./CONTRIBUTING.md) before you proceed. This project uses [tools](https://vincent.click/toolkit) that run on [Powershell Core](https://microsoft.com/PowerShell). To get started,
```ps1
./tools help
```
## Copyright
Copyright 2019-2021 [Vincent Fiestada](mailto:vincent@vincent.click). This project is released under an [MIT License](./license).
Icon made by [Freepik](http://www.freepik.com/).