Giter Club home page Giter Club logo

golog's Introduction

Golog - Another logger written in Go

image

The main golog features are:

  • Zero(1) allocations
  • Color support (also on windows!)
  • Debug mode controllable via environment variable
  • Looks good(2)
  • Modules thanks to which you know where the logs come from
  • Arguments configurable for each log message independently
  • Hooks which add specific information to every log message that uses a hook with the same name
  • Sentry and Discord integration (via plugins)
  • Built-in panic recovery function
  • File path with line and stack trace support
  • Potential for many integrations and plugins

We also plan to add PostgreSQL (and maybe MongoDB) integration with a dashboard.

(1) - IT IS zero allocation logger if you don't use many arguments or specific formatting. Internally it does not make any allocation.

(2) - We don't provide any way to change message style or colors

Most methods and types are not documented as they are pretty straightforward - their names say everything.

Installation

Just run go get github.com/BOOMfinity/golog in your project directory

Plugins

Sentry.io integration - Repository - go get github.com/BOOMfinity/golog-sentry

Discord webhook integration - Repository - go get github.com/BOOMfinity/golog-discord (Currently not available as our Discord library is private)

Examples

Simple "Hello World!" message:

package main

import "github.com/BOOMfinity/golog"

func main() {
	log := golog.New("main")
	log.Info().Send("Hello World!")
}

Simple http server log message:

package main

import "github.com/BOOMfinity/golog"

func main() {
	log := golog.New("web-server")
	userIP := "127.0.0.1"
	reqPath := "/users/test-1"
	reqMethod := "GET"
	log.Info().Add("%v %v", reqMethod, reqPath).Any(userIP).Send("new request!")
}

Modules example

package main

import "github.com/BOOMfinity/golog"

func main() {
	log := golog.New("cmd").SetLevel(golog.LevelDebug)
	log.Info().Send("Ready!")
	apiLog := log.Module("api")
	apiLog.Warn().Send("Debug mode is enabled")
	usersLog := apiLog.Module("users")
	usersLog.Debug().Send("Nickname changed")
}

Errors and panics

package main

import "github.com/BOOMfinity/golog"

func main() {
	log := golog.New("cmd")
	defer log.Recover()
	log.Error().FileWithLine().Stack().Send("error message with stack and file")
	x() // panic will be caught by log.Recover
}

func x() {
	panic("fatal error D:")
}

Internal environment variables

There are two special, global environment variables that can be used with golog.

  • GOLOG_DEBUG or GDEBUG = on | true - If set to "true" it will globally enable "debug" level for all instances in application.

  • GOLOG_COLORS_DISABLED = on | yes | true - If for some reason you want to disable colors, set this env variable to "true".

golog's People

Contributors

venompcpl avatar unxcepted avatar

Stargazers

MrBoombastic avatar

Watchers

MrBoombastic avatar  avatar

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.