Git Product home page Git Product logo

go-logger's Introduction

Logging for Console and GCP

Common Interface logger.ILogger

The ILogger interface is a common interface for all loggers in this package. It provides the ability, to use e.g. clog for unit test and gcplog for production.

clog

clog or "console-log" is a convenience wrapper around github.com/rs/zerolog that makes it easy and intuitive to use. The default stdout logging produces nice and colourful log statements on linux consoles. The logger accepts multiple io.Writers that will output log statements in JSON form. The fields are

  • level the log-level (TRACE, DEBUG, INFO, WARN, ERROR)
  • module the name of the "module" that was given when the logger was initialized
  • host hostname of the machine, running the application
  • time timestamp
  • message the log message, whatever that may be.
{
	"level":   "info",
	"module":  "MyModule",
	"host":    "svrl1midtoolt51",
	"time":    "2022-03-28T09:35:14.769433+02:00",
	"message": "This is a INFO logging statement."
}

Usage

Dedicated logger

The dedicated logger is the default way to use clog. A logger can be initialized with a "Module" parameter, that helps to separate different loggers from different modules, meaning each module can use it's own logger and output will be prefixed accodingly.

out1 := &bytes.Buffer{} // or any other IO.writer
out2 := &bytes.Buffer{} // or any other IO.writer

ll := clog.New("MyTestApplication", clog.DEBUG, true, out1, out2)
defer ll.Close()

ll.Info("This is an Info Statement")

gcplog

Usage

ll, err := gcplog.New("MyTestApplication", logger.DEBUG)
if err != nil {
	panic(err)
}
defer ll.Close()

ll.Info("This is an Info Statement")

go-logger's People

Contributors

infomaniac avatar

Watchers

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