Simple and blazing fast lockfree logging library for golang

Overview

License: MIT release CircleCI codecov Codacy Badge Go Report Card GolangCI Go Walker GoDoc DepShield Badge FOSSA Status

glg is simple golang logging library

Requirement

Go 1.11

Installation

go get github.com/kpango/glg

Example

package main

import (
	"net/http"
	"time"

	"github.com/kpango/glg"
)

// NetWorkLogger sample network logger
type NetWorkLogger struct{}

func (n NetWorkLogger) Write(b []byte) (int, error) {
	// http.Post("localhost:8080/log", "", bytes.NewReader(b))
	http.Get("http://127.0.0.1:8080/log")
	glg.Success("Requested")
	glg.Infof("RawString is %s", glg.RawString(b))
	return 1, nil
}

func main() {

	// var errWriter io.Writer
	// var customWriter io.Writer
	infolog := glg.FileWriter("/tmp/info.log", 0666)

	customTag := "FINE"
	customErrTag := "CRIT"

	errlog := glg.FileWriter("/tmp/error.log", 0666)
	defer infolog.Close()
	defer errlog.Close()
	glg.Get().
		SetMode(glg.BOTH). // default is STD
		// DisableColor().
		// SetMode(glg.NONE).
		// SetMode(glg.WRITER).
		// SetMode(glg.BOTH).
		// InitWriter().
		// AddWriter(customWriter).
		// SetWriter(customWriter).
		// AddLevelWriter(glg.LOG, customWriter).
		// AddLevelWriter(glg.INFO, customWriter).
		// AddLevelWriter(glg.WARN, customWriter).
		// AddLevelWriter(glg.ERR, customWriter).
		// SetLevelWriter(glg.LOG, customWriter).
		// SetLevelWriter(glg.INFO, customWriter).
		// SetLevelWriter(glg.WARN, customWriter).
		// SetLevelWriter(glg.ERR, customWriter).
		AddLevelWriter(glg.INFO, infolog).                         // add info log file destination
		AddLevelWriter(glg.ERR, errlog).                           // add error log file destination
		AddStdLevel(customTag, glg.STD, false).                    //user custom log level
		AddErrLevel(customErrTag, glg.STD, true).                  // user custom error log level
		SetLevelColor(glg.TagStringToLevel(customTag), glg.Cyan).  // set color output to user custom level
		SetLevelColor(glg.TagStringToLevel(customErrTag), glg.Red) // set color output to user custom level

	glg.Info("info")
	glg.Infof("%s : %s", "info", "formatted")
	glg.Log("log")
	glg.Logf("%s : %s", "info", "formatted")
	glg.Debug("debug")
	glg.Debugf("%s : %s", "info", "formatted")
	glg.Warn("warn")
	glg.Warnf("%s : %s", "info", "formatted")
	glg.Error("error")
	glg.Errorf("%s : %s", "info", "formatted")
	glg.Success("ok")
	glg.Successf("%s : %s", "info", "formatted")
	glg.Fail("fail")
	glg.Failf("%s : %s", "info", "formatted")
	glg.Print("Print")
	glg.Println("Println")
	glg.Printf("%s : %s", "printf", "formatted")
	glg.CustomLog(customTag, "custom logging")
	glg.CustomLog(customErrTag, "custom error logging")

	glg.Get().AddLevelWriter(glg.DEBG, NetWorkLogger{}) // add info log file destination

	http.Handle("/glg", glg.HTTPLoggerFunc("glg sample", func(w http.ResponseWriter, r *http.Request) {
		glg.New().
		AddLevelWriter(glg.Info, NetWorkLogger{}).
		AddLevelWriter(glg.Info, w).
		Info("glg HTTP server logger sample")
	}))

	http.ListenAndServe("port", nil)

	// fatal logging
	glg.Fatalln("fatal")
}

Benchmarks

Contribution

  1. Fork it ( https://github.com/kpango/glg/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

kpango

LICENSE

glg released under MIT license, refer LICENSE file.
FOSSA Status

Comments
  • Logging function returns error affects program test coverage and maintainability

    Logging function returns error affects program test coverage and maintainability

    When using logging function provided by glg (for example Print, Printf, Errorf, etc), we have to handle the returned error from the function. It makes the program hard to maintain and affect the implementation of test cases to handle the error properly.

    opened by kevindiu 6
  • Disable time printing

    Disable time printing

    Hello, thank you for nice library!

    Is there a way to disable time printing? If one logs to systemd, it is quite redundant as journald adds its own timestamps...

    enhancement help wanted wontfix 
    opened by vlada-dudr 5
  • glg.Fatal trace file line is wrong

    glg.Fatal trace file line is wrong

    glg.Fatal(errors.New("a error"))
    

    output is:

    2022-08-30 17:35:53	[FATAL]:	(/home/del0/projects/xyz/source/vendor/github.com/kpango/glg/glg.go:1383):	a error
    
    opened by electricface 3
  • Support logging message callback such as DebugFunc(func() string)

    Support logging message callback such as DebugFunc(func() string)

    For example, if we do logging with some complex object,

    if glg.Get().GetCurrentMode(glg.DEBG) != glg.NONE {
    	rawpol, _ := json.Marshal(data)
    	glg.Debugf("%s", (string)(data))
    }
    

    , if glg support something like this, it may be better.

    glg.DebugFunc(func() string {
    	// do whatever you want
    })
    
    WIP 
    opened by kevindiu 3
  • STD only WARN and up levels

    STD only WARN and up levels

    I would like to have the ability to show only some of the log levels into the STD out. Currently, New function (constructor) add all levels to the STD by default and it can't be changed (or it can?)

    opened by spolischook 2
  • Tricky way of printing buffer

    Tricky way of printing buffer

    I found that code into the Glg.out method:

    _, err = fmt.Fprintf(log.writer, *(*string)(unsafe.Pointer(&buf)), val...)
    

    I guess you have a serious reason to get data from buf in such a tricky way. I'm curious why you do so?

    @kpango

    opened by spolischook 2
  • New LTraceLine broke compilation on android

    New LTraceLine broke compilation on android

    https://github.com/kpango/glg/blob/6cfd022d5fa924304b38df3111014ff289c4cd0e/glg.go#L149

    /var/folders/9w/h3xyrgx538g23bw10m59tbgc0000gn/T/gomobile-work-454342767/pkg/mod/github.com/kpango/[email protected]/glg.go:234:4: constant 2147483648 overflows int /var/folders/9w/h3xyrgx538g23bw10m59tbgc0000gn/T/gomobile-work-454342767/pkg/mod/github.com/kpango/[email protected]/glg.go:241:4: constant 2147483648 overflows int /var/folders/9w/h3xyrgx538g23bw10m59tbgc0000gn/T/gomobile-work-454342767/pkg/mod/github.com/kpango/[email protected]/glg.go:248:4: constant 2147483648 overflows int /var/folders/9w/h3xyrgx538g23bw10m59tbgc0000gn/T/gomobile-work-454342767/pkg/mod/github.com/kpango/[email protected]/glg.go:255:4: constant 2147483648 overflows int /var/folders/9w/h3xyrgx538g23bw10m59tbgc0000gn/T/gomobile-work-454342767/pkg/mod/github.com/kpango/[email protected]/glg.go:262:4: constant 2147483648 overflows int /var/folders/9w/h3xyrgx538g23bw10m59tbgc0000gn/T/gomobile-work-454342767/pkg/mod/github.com/kpango/[email protected]/glg.go:269:4: constant 2147483648 overflows int /var/folders/9w/h3xyrgx538g23bw10m59tbgc0000gn/T/gomobile-work-454342767/pkg/mod/github.com/kpango/[email protected]/glg.go:276:4: constant 2147483648 overflows int /var/folders/9w/h3xyrgx538g23bw10m59tbgc0000gn/T/gomobile-work-454342767/pkg/mod/github.com/kpango/[email protected]/glg.go:284:4: constant 4294967296 overflows int /var/folders/9w/h3xyrgx538g23bw10m59tbgc0000gn/T/gomobile-work-454342767/pkg/mod/github.com/kpango/[email protected]/glg.go:291:4: constant 4294967296 overflows int /var/folders/9w/h3xyrgx538g23bw10m59tbgc0000gn/T/gomobile-work-454342767/pkg/mod/github.com/kpango/[email protected]/glg.go:298:4: constant 8589934592 overflows int /var/folders/9w/h3xyrgx538g23bw10m59tbgc0000gn/T/gomobile-work-454342767/pkg/mod/github.com/kpango/[email protected]/glg.go:298:4: too many errors gomobile: go build -v -buildmode=c-shared -o=/var/folders/9w/h3xyrgx538g23bw10m59tbgc0000gn/T/gomobile-work-454342767/android/src/main/jniLibs/armeabi-v7a/libgojni.so ./gobind failed: exit status 2

    used command: gomobile bind -v --target=android .

    Could you please a normal value for your enumeration ?

    Would be worth it to add also a github actions job that build on all platform just to be sure we are always compatible, using gomobile it's should be straightforward

    opened by Milerius 2
  • Update module go.uber.org/zap to v1.18.1

    Update module go.uber.org/zap to v1.18.1

    WhiteSource Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | go.uber.org/zap | require | minor | v1.17.0 -> v1.18.1 |


    Release Notes

    uber-go/zap

    v1.18.1

    Compare Source

    Bugfixes:

    • #​974: Fix nil dereference in logger constructed by zap.NewNop.

    v1.18.0

    Compare Source

    Enhancements:

    • #​961: Add zapcore.BufferedWriteSyncer, a new WriteSyncer that buffers messages in-memory and flushes them periodically.
    • #​971: Add zapio.Writer to use a Zap logger as an io.Writer.
    • #​897: Add zap.WithClock option to control the source of time via the new zapcore.Clock interface.
    • #​949: Avoid panicking in zap.SugaredLogger when arguments of *w methods don't match expectations.
    • #​943: Add support for filtering by level or arbitrary matcher function to zaptest/observer.
    • #​691: Comply with io.StringWriter and io.ByteWriter in Zap's buffer.Buffer.

    Thanks to @​atrn0, @​ernado, @​heyanfu, @​hnlq715, @​zchee for their contributions to this release.


    Configuration

    📅 Schedule: At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box.

    This PR has been generated by WhiteSource Renovate. View repository job log here.

    opened by renovate[bot] 2
  • Update module github.com/goccy/go-json to v0.7.4

    Update module github.com/goccy/go-json to v0.7.4

    WhiteSource Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | github.com/goccy/go-json | require | patch | v0.7.1 -> v0.7.4 |


    Release Notes

    goccy/go-json

    v0.7.4

    Compare Source

    • Fix encoding of indirect layout structure ( #​264 )

    v0.7.3

    Compare Source

    • Fix encoding of pointer type in empty interface ( #​262 )

    v0.7.2

    Compare Source

    Fix decoder
    • Add decoder for func type to fix decoding of nil function value ( #​257 )
    • Fix stream decoding of []byte type ( #​258 )
    Performance
    • Improve decoding performance of map[string]interface{} type ( use mapassign_faststr ) ( #​256 )
    • Improve encoding performance of empty interface type ( remove recursive calling of vm.Run ) ( #​259 )
    Benchmark
    • Add bytedance/sonic as benchmark target ( #​254 )

    Configuration

    📅 Schedule: At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box.

    This PR has been generated by WhiteSource Renovate. View repository job log here.

    opened by renovate[bot] 2
  • Update module github.com/goccy/go-json to v0.7.1

    Update module github.com/goccy/go-json to v0.7.1

    WhiteSource Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | github.com/goccy/go-json | require | patch | v0.7.0 -> v0.7.1 |


    Release Notes

    goccy/go-json

    v0.7.1

    Compare Source

    Fix decoder
    • Fix error when unmarshal empty array ( #​253 )

    Configuration

    📅 Schedule: At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box.

    This PR has been generated by WhiteSource Renovate. View repository job log here.

    opened by renovate[bot] 2
  • Update module github.com/goccy/go-json to v0.5.1

    Update module github.com/goccy/go-json to v0.5.1

    WhiteSource Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | github.com/goccy/go-json | require | patch | v0.5.0 -> v0.5.1 |


    Release Notes

    goccy/go-json

    v0.5.1

    Compare Source

    Optimization
    • Add type addrShift to enable bigger encoder/decoder cache ( #​213 )
    Fix decoder
    • Keep original reference of slice element ( #​229 )
    Refactor
    • Refactor Debug mode for encoding ( #​226 )
    • Generate VM sources for encoding ( #​227 )
    • Refactor validator for null/true/false for decoding ( #​221 )

    Configuration

    📅 Schedule: At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    ♻️ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box.

    This PR has been generated by WhiteSource Renovate. View repository job log here.

    opened by renovate[bot] 2
  • Log the context

    Log the context

    🚀Log the context

    Description: There are many different contexts that we need to log along with basic log message

    ### Issue with current implementation 
    
    At BajaBikes, we used glg to log app executions in many different contexts:
    - User, admin, demon execution processes
    - lambda, cube, local 
    - dev, staging, production
    Some of that contexts, e.g. last one, could implemented by separate logging endpoints and\or writers
    But others should be added to log as part of the logging.  
    E.g. [Elastic Common Schema (ECS)](https://www.elastic.co/guide/en/ecs/current/index.html) 
    has a rich schema that can complete log context in many ways. 
    
    ### Applicable Solution
    
    Use json format only for one (LogstashWriter) writer  
    In writer before send our logs we can Unmarshal log, add contexts and then Marshal it back.  
    We can use json format only for all writers all together, that is not trully readable (e.g. for a console)
    
    Another solution will be allow add context to log somehow, or allow define custom structure for a logs,  
    but I can't imagine an implementation for now.
    
    ### Alternative solution
    
    For now, we are using text format, that we parse in writer by regular expresion, complete structure with contexts, 
    marshal it and send to the logstash. 
    It's fine for now, but maybe you can get sugestions to make more powerful architecture
    
    
    opened by spolischook 2
Releases(v1.6.13)
Owner
Yusuke Kato
Yahoo! JAPAN Tech Lab
Yusuke Kato
Tiny structured logging abstraction or facade for various logging libraries, allowing the end user to plug in the desired logging library in main.go

Tiny structured logging abstraction or facade for various logging libraries, allowing the end user to plug in the desired logging library in main.go.

Jacek Olszak 12 Jul 30, 2022
Golog is a logger which support tracing and other custom behaviors out of the box. Blazing fast and simple to use.

GOLOG Golog is an opinionated Go logger with simple APIs and configurable behavior. Why another logger? Golog is designed to address mainly two issues

Damiano Petrungaro 35 Sep 10, 2022
Blazing fast syslog parser

A parser for Syslog messages and transports. Blazing fast Syslog parsers By @leodido. To wrap up, this package provides: a RFC5424-compliant parser an

InfluxData 425 Sep 26, 2022
A simple logging module for go, with a rotating file feature and console logging.

A simple logging module for go, with a rotating file feature and console logging. Installation go get github.com/jbrodriguez/mlog Usage Sample usage W

Juan B. Rodriguez 26 Sep 2, 2022
Gomol is a library for structured, multiple-output logging for Go with extensible logging outputs

gomol Gomol (Go Multi-Output Logger) is an MIT-licensed structured logging library for Go. Gomol grew from a desire to have a structured logging libra

Kristin Davidson 18 Sep 2, 2022
FactorLog is a logging infrastructure for Go that provides numerous logging functions for whatever your style may be

FactorLog FactorLog is a fast logging infrastructure for Go that provides numerous logging functions for whatever your style may be. It could easily b

Kevin Darlington 55 Aug 3, 2022
Package logging implements a logging infrastructure for Go

Golang logging library Package logging implements a logging infrastructure for Go. Its output format is customizable and supports different logging ba

Luke Zhang 0 Nov 10, 2021
Parametrized JSON logging library in Golang which lets you obfuscate sensitive data and marshal any kind of content.

Noodlog Summary Noodlog is a Golang JSON parametrized and highly configurable logging library. It allows you to: print go structs as JSON messages; pr

Gyoza Tech 38 Sep 16, 2022
Simple and configurable Logging in Go, with level, formatters and writers

go-log Logging package similar to log4j for the Golang. Support dynamic log level Support customized formatter TextFormatter JSONFormatter Support mul

Guoqiang Chen 12 May 23, 2022
Logging library for Golang

GLO Logging library for Golang Inspired by Monolog for PHP, severity levels are identical Install go get github.com/lajosbencz/glo Severity levels Deb

Lajos Bencz 14 Aug 26, 2021
Golang logging library

Golang logging library Package logging implements a logging infrastructure for Go. Its output format is customizable and supports different logging ba

Örjan Fors 1.8k Sep 14, 2022
Cloud logging library in golang

?? logg Open Source Cloud logging library in Go. About the project Connect your golang microservices logs with this engine! Send your logs to kafka, r

yuri 3 Nov 8, 2021
The Simplest and worst logging library ever written

gologger A Simple Easy to use go logger library. Displays Colored log into console in any unix or windows platform. You can even store your logs in fi

Sadlil Rhythom 40 Jul 16, 2022
Seelog is a native Go logging library that provides flexible asynchronous dispatching, filtering, and formatting.

Seelog Seelog is a powerful and easy-to-learn logging framework that provides functionality for flexible dispatching, filtering, and formatting log me

Seelog project repository 1.6k Sep 16, 2022
Hierarchical, leveled, and structured logging library for Go

spacelog Please see http://godoc.org/github.com/spacemonkeygo/spacelog for info License Copyright (C) 2014 Space Monkey, Inc. Licensed under the Apach

Space Monkey Go 98 Apr 27, 2021
Simple, configurable and scalable Structured Logging for Go.

log Log is a simple, highly configurable, Structured Logging library Why another logging library? There's allot of great stuff out there, but also tho

Go Playgound 281 Sep 1, 2022
Simple, customizable, leveled and efficient logging in Go

log Simple, customizable, leveled and efficient logging in Go Installation go get -u github.com/ermanimer/log Features log is a simple logging package

Erman İmer 21 Dec 20, 2021
Minimalistic logging library for Go.

logger Minimalistic logging library for Go. Blog Post Features: Advanced output filters (package and/or level) Attributes Timers for measuring perform

Azer Koçulu 156 Sep 1, 2022
A pure Go contextual logging library with "batteries included"

Cue Overview Cue implements contextual logging with "batteries included". It has thorough test coverage and supports logging to stdout/stderr, file, s

Bob Ziuchkovski 26 Sep 16, 2019