Coder Social home page Coder Social logo

nlog's Introduction

nlog

Node Logger, fast and thread-safe logger for Golang

Colored

Node Logger is a KISS (Keep It Simple, Stupid) logger that
suits most people. It is much faster than Logrus and Log15, and asymtotically as fast as Logxi.

The motivation for writing this logger is that none of the other loggers seems to be thread-safe and even they are buggy. I sacrificed fancy features in favour of performance and safety.

Please feel free to suggest features and pull requests.

Install

go get github.com/mehdioa/nlog

Example

package main

import "github.com/mehdioa/nlog"

var log *nlog.Logger

func main() {
	formatter := nlog.NewTextFormatter(true, true)
	log = nlog.NewLogger(nlog.DebugLevel, formatter)
	log.Debugf("Logging without a node is possible")
	
	sNode := log.New("Server", nlog.Data{"Protocol": "tcp", "Port": 12542})
	sNode.Debugf("Server is serving")

	cNode := sNode.NewNode("Client", nlog.Data{"RemoteAddr": "[::1]9183", "error": nil})
	cNode.Infof("Client is serving")
}

Formatters

The built-in logging formatters are:

  • nlog.NewTextFormatter(show_caller, enable_color bool).
  • nlog.NewJsonFormatter(show_caller bool). Logs fields as JSON.

Use NLog in your library

The best way to use nlog in your library is to define

package customPackage

import "github.com/mehdioa/nlog"

var log *nlog.Logger

func SetLogger(logger *nlog.Logger) {
	log = logger
}

and then use this log in your library. Just remember to initialize a Logger in your application and call

package main

import "customPackage"

var logger *nlog.Logger

func main() {
	formatter := nlog.NewTextFormatter(true, true)
	log = nlog.NewLogger(nlog.DebugLevel, formatter)
	
	customPackage.SetLogger(log)	
}

nlog's People

Contributors

mehdioa avatar omidnikta avatar mtanski avatar

Stargazers

Alex Barkan avatar Joseph M. Sleiman avatar  avatar dryaf avatar

Watchers

Shawn Butts avatar James Cloos 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.