GithubHelp home page GithubHelp logo

logger's Introduction

Logger

Logger provides a simple facade over most popular logging systems for GoLang, allowing you to log in your application without vendor lock-in. Think SLF4J for GoLang.

Total alerts Language grade: Go

Usage

Import dependencies. Use latest version.

import (
	github.com/xmlking/logger v0.1.4
    // required: your choice of logger plugins
	github.com/xmlking/logger/zerolog v0.1.4
    //optional: gormlog
	github.com/xmlking/logger/gormlog v0.1.4

)

Default logger

func ExampleLog() {
	logger.DefaultLogger = logger.NewLogger(logger.WithOutput(os.Stdout), logger.WithTimeFormat("ddd"))

	log.Info("test show info: ", "msg ", true, 45.65)
	log.Infof("test show infof: name: %s, age: %d", "sumo", 99)
	log.WithFields(map[string]interface{}{
		"name":  "sumo",
		"age":   99,
		"alive": true,
	}).Info("test show fields")
	log.WithError(errors.New("error message")).Errorf("Testing: %s", "WithError")
	// Output:
	//{"level":"info","message":"test show info: msg true 45.65","time":"ddd"}
	//{"level":"info","message":"test show infof: name: sumo, age: 99","time":"ddd"}
	//{"age":99,"alive":true,"level":"info","message":"test show fields","name":"sumo","time":"ddd"}
	//{"error":"error message","level":"error","message":"Testing: WithError","time":"ddd"}
}

Zerolog logger

func ExampleWithFields() {
	logger.DefaultLogger = zerolog.NewLogger(
		logger.WithOutput(os.Stdout),
		logger.WithTimeFormat("ddd"),
		zerolog.WithProductionMode(),
	)

	log.Info("testing: Info")
	log.Infof("testing: %s", "Infof")
	log.WithFields(map[string]interface{}{
		"name":  "sumo",
		"age":   99,
		"alive": true,
	}).Info("testing: with fields")
	// Output:
	// {"level":"info","time":"ddd","message":"testing: Info"}
	// {"level":"info","time":"ddd","message":"testing: Infof"}
	// {"level":"info","age":99,"human":true,"sumo":"demo","time":"ddd","message":"testing: with fields"}
}

For Contributors

Prerequisites

brew install hub
# goup checks if there are any updates for imports in your module.
GO111MODULE=on go get github.com/rvflash/goup
# for static check/linter
GO111MODULE=off go get github.com/golangci/golangci-lint/cmd/golangci-lint

Test

make download
make test
make bench
# Benchmark specific test
cd zerolog
go test -run=^$ -bench=^BenchmarkInfoLog ./...
go test -run=^$ -bench=^BenchmarkInfoLog -benchtime 15s -count 2 -cpu 1,2,4 ./...
# Results:
# zerolog: 326443       3866 ns/op
# wrapper: 324487       4280 ns/op

Release

make download
git add .
# Start release on develop branch
git flow release start v0.1.0
# on release branch
git-chglog -c .github/chglog/config.yml -o CHANGELOG.md --next-tag v0.1.0
# update `github.com/xmlking/logger` version in each `go.mod` file.
# commit all changes.
# finish release on release branch
git flow release finish
# on master branch, (gpoat = git push origin --all && git push origin --tags)
gpoat
# add git tags for sub-modules
make release TAG=v0.1.0

Reference

logger's People

Contributors

xmlking avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

logger's Issues

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

gomod
gormlog/go.mod
  • github.com/xmlking/logger v0.1.5
logrus/go.mod
  • github.com/pkg/errors v0.9.1
  • github.com/sirupsen/logrus v1.4.2
  • github.com/xmlking/logger v0.1.4
zap/go.mod
  • github.com/pkg/errors v0.9.1
  • github.com/xmlking/logger v0.1.5
  • go.uber.org/zap v1.14.1
zerolog/go.mod
  • github.com/pkg/errors v0.9.1
  • github.com/rs/zerolog v1.18.0
  • github.com/xmlking/logger v0.1.5

  • Check this box to trigger a request for Renovate to run again on this repository

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.