/captainslog

A simple but powerful logging library for Go

Primary LanguageGoMIT LicenseMIT

captainslog

Go Reference Conventional Commits License: BSD-3

A simple logging library for Go

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

Screenshot of captainslog in action

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.

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 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 before you proceed. This project uses tools that run on Powershell Core. To get started,

./tools help

Copyright

Copyright 2019-2021 Vincent Fiestada. This project is released under an MIT License.

Icon made by Freepik.