Giter Club home page Giter Club logo

log-go's Introduction

log-go

Log-go is a logging library developed with simplicity and thread-safety in mind. It doesn't support any extra-fancy features. Just like Go itself.

If you wish to improve upon this, you are welcome to send me a Pull Request.

Example with Colors

Demo

Features

  • Different log levels like Fatal, Error, Info, etc.
  • Configurable buffered writer (os.Stdout, *File, etc.)
  • Thread safety
  • Prefixes to separate logs from everything else
  • Extremely simple setup
  • Optionally coloured terminal output
  • Well-tested

Log Levels

This library comes with the following log levels:

  1. Panic
  2. Fatal
  3. Error
  4. Warn
  5. Info
  6. Debug

These are enumerated as LevelDebug, LevelInfo, etc., so that you won't have to memorise them by numbers.

Each Log instance has five methods that are named precisely after the levels. As well as their formatted counterparts Debugf, Infof, Errorf, etc. Use them like so:

logger := log.Default()
logger.Warn("this is a warning")
logger.Infof("this is an information message #%d", 42)
package main

import (
	"os"
	"github.com/sharpvik/log-go"
)

func init() {
	// Change log level.
	log.SetLevel(log.LevelInfo) // default: LevelError

	// Change log writer.
	file, _ := os.Create("server.log")
	log.SetWriter(file) // default: os.Stdout
}

func main() {
	// Computations ...
	x := 40 + 2

	// Print log with priority level Info.
	log.Infof("x = %d", x)
	// * 11/01/2021 23:07:08 INFO  x = 42
}

Examples

You are welcome to look at some examples too!

log-go's People

Contributors

sharpvik avatar

Watchers

 avatar

log-go's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.