Code Monkey home page Code Monkey logo

logng's Introduction

logng

Go Reference Maintainability Rating Quality Gate Status

logng is a Go (Golang) package that provides structured and leveled logging.

Features

  • Leveled logging: FATAL, ERROR, WARNING, INFO, DEBUG
  • Verbose support
  • Text and JSON output
  • Customizable output
  • Function and file logging
  • Stack trace logging
  • Field support
  • Performance optimized

Installation

You can install logng using the go get command:

go get github.com/goinsane/logng/v2

Examples

Basic example

package main

import (
	"errors"

	"github.com/goinsane/logng/v2"
)

func main() {
	// log by severity and verbosity.
	// default Logger's severity is SeverityInfo.
	// default Logger's verbose is 0.
	logng.Debug("this is debug log. it won't be shown.")
	logng.Info("this is info log.")
	logng.Warning("this is warning log.")
	logng.V(1).Error("this is error log, verbosity 1. it won't be shown.")

	// set stack trace severity
	logng.SetStackTraceSeverity(logng.SeverityWarning)

	// logs with stack trace, because the log severity is warning
	logng.Warningf("a warning: %w", errors.New("unknown"))

	// log with fields
	logger := logng.WithFieldKeyVals("user_name", "john", "ip", "1.2.3.4")
	logger.Infof("connected user:\n%s", "John Smith")

	// logs with fields and stack trace
	logger.Error("an error")
}
2023/11/21 16:18:37 INFO - this is info log.
2023/11/21 16:18:37 WARNING - this is warning log.
2023/11/21 16:18:37 WARNING - a warning: unknown
    
	main.main(0x104d6f7b0)
		main.go:22 +0x150
	runtime.main(0x104d0a2e0)
		proc.go:250 +0x247
	runtime.goexit(0x104d35390)
		asm_arm64.s:1172 +0x3
    
2023/11/21 16:18:37 INFO - connected user:
                           John Smith
    
	+ "user_name"="john" "ip"="1.2.3.4"
    
2023/11/21 16:18:37 ERROR - an error
    
	+ "user_name"="john" "ip"="1.2.3.4"
    
	main.main(0x104d6f7b0)
		main.go:29 +0x248
	runtime.main(0x104d0a2e0)
		proc.go:250 +0x247
	runtime.goexit(0x104d35390)
		asm_arm64.s:1172 +0x3
    

More examples

To run any example, please use the command like the following:

cd examples/example1/
go run *.go

Tests

To run all tests, please use the following command:

go test -v

To run all examples, please use the following command:

go test -v -run=^Example

To run all benchmarks, please use the following command:

go test -v -run=^Benchmark -bench=.

Contributing

We welcome contributions from the community to improve and expand project capabilities. If you find a bug, have a feature request, or want to contribute code, please follow our guidelines for contributing (CONTRIBUTING.md) and submit a pull request.

License

This project is licensed under the BSD 3-Clause License.

logng's People

Contributors

orkunkaraduman avatar

Stargazers

Mustafa KÖSE avatar Yunus 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.