Giter Club home page Giter Club logo

logger's Introduction

Logger

Logger package implements logging methods with formatted output and more detailed logging information than provided in the standard logging package of golang. It is possible to specify the level of logging information to be written as output.

Usage

setLevel(level LogLevel)

sets the level of logging information written as output.

There are four possible values for argument level of type LogLevel in ascending info order:

  1. LEVEL_ERROR: Only Error logs are written to stderr.
  2. LEVEL_WARNING: Warnings and errors are written to stderr.
  3. LEVEL_INFO: Errors and warnings are written to stderr, infos to stdout.
  4. LEVEL_DEBUG: Errors and warnings are written to stderr, infos and debugs to stdout.

To print logging information you can choose one of the following *log.Logger variables chaining to common I/O writers:

Error
Warning
Info
Debug

The following Log flags are set:

log.Ldate: the date in the local time zone
log.Ltime: the time in the local time zone
log.Lshortfile: final file name element and line number
log.Lmsgprefix: move the "prefix" log level tag from the beginning of the line to before the message

Examples

logger.SetLevel(logger.LEVEL_WARNING)
suffix := 2
logger.Error.Printf("error %d", suffix)
logger.Warning.Printf("warning  %d", suffix)
logger.Info.Printf("info  %d", suffix)
logger.Debug.Printf("debug  %d", suffix)

has the following output:

2021/10/07 12:18:12 main.go:16: [ERROR]: error 2
2021/10/07 12:18:12 main.go:17: [WARNING]: warning  2
logger.SetLevel(logger.LEVEL_DEBUG)
suffix := 4
logger.Error.Printf("error %d", suffix)
logger.Warning.Printf("warning  %d", suffix)
logger.Info.Printf("info  %d", suffix)
logger.Debug.Printf("debug  %d", suffix)

prints all logging information:

2021/10/07 12:18:12 main.go:32: [ERROR]: error 4
2021/10/07 12:18:12 main.go:33: [WARNING]: warning  4
2021/10/07 12:18:12 main.go:34: [INFO]: info  4
2021/10/07 12:18:12 main.go:35: [DEBUG]: debug  4

Tests

To perform the unit tests, you can call from the root folder:

go test

To run the example:

go run example/main.go

License

Apache License 2.0

logger's People

Contributors

kevinbrendel avatar kschneider84 avatar phev8 avatar

Watchers

 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.