Giter VIP home page Giter VIP logo

logger's Introduction

logger for OpenPitrix

Build Status Go Report Card GoDoc License

Install

  1. Install Go1.11+
  2. set GO111MODULE=on
  3. go get openpitrix.io/logger
  4. go run hello.go

Example

package main

import (
	"bytes"
	"context"
	"fmt"

	"openpitrix.io/logger"
	"openpitrix.io/logger/ctxutil"
)

func main() {
	logger.Infof(nil, "hello1 openpitrix")

	logger.HideCallstack()
	logger.Infof(nil, "hello2 openpitrix")

	logger.ShowCallstack()
	logger.Infof(nil, "hello3 openpitrix")

	{
		var buf bytes.Buffer
		logger := logger.New().SetOutput(&buf)

		logger.Infof(nil, "hello4 openpitrix")
		logger.Infof(nil, "hello5 openpitrix\nlogger")
		logger.Infof(nil, "")

		fmt.Print(buf.String())
	}

	ctx := context.Background()
	ctx = ctxutil.SetRequestId(ctx, "req-id-001")

	logger.Infof(ctx, "hello context1")

	ctx = ctxutil.SetMessageId(ctx, "msg-001", "msg-002")
	logger.Infof(ctx, "hello context2")

	ctx = ctxutil.ClearRequestId(ctx)
	logger.Infof(ctx, "hello context3")
}

output:

2018-10-20 07:43:31.70066 -INFO- hello1 openpitrix (hello.go:19)
2018-10-20 07:43:31.70085 -INFO- hello2 openpitrix
2018-10-20 07:43:31.70086 -INFO- hello3 openpitrix (hello.go:25)
2018-10-20 07:43:31.70089 -INFO- hello4 openpitrix (hello.go:31)
2018-10-20 07:43:31.70091 -INFO- hello5 openpitrix\nlogger (hello.go:32)
2018-10-20 07:43:31.70093 -INFO-  (hello.go:33)
2018-10-20 07:43:31.70096 -INFO- hello context1 (hello.go:41){@req-id-001}
2018-10-20 07:43:31.70099 -INFO- hello context2 (hello.go:44){msg-001|msg-002@req-id-001}
2018-10-20 07:43:31.70101 -INFO- hello context3 (hello.go:47){msg-001|msg-002@}

logger's People

Contributors

chai2010 avatar

Watchers

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