An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

![](./icon.svg)

# captainslog

[![](https://github.com/vncntx/captainslog/workflows/Unit%20Tests/badge.svg)](https://github.com/vncntx/captainslog/actions?query=workflow%3A%22Unit+Tests%22)
[![](https://github.com/vncntx/captainslog/workflows/Style%20Checks/badge.svg)](https://github.com/vncntx/captainslog/actions?query=workflow%3A%22Style+Checks%22)
[![Go Reference](https://img.shields.io/badge/reference-007d9c.svg?labelColor=16161b&logo=go&logoColor=white)](https://pkg.go.dev/vincent.click/pkg/captainslog/v2?tab=doc)
[![Conventional Commits](https://img.shields.io/badge/commits-conventional-0047ab.svg?labelColor=16161b)](https://conventionalcommits.org)
[![License: BSD-3](https://img.shields.io/github/license/vncntx/captainslog.svg?labelColor=16161b&color=0047ab)](./license)

A simple logging library for [Go](https://golang.org/)

- cross-platform colors
- multiple log levels
- structured logging
- caller detection

![Screenshot of captainslog in action](./assets/demo.png)

## 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/).