GithubHelp home page GithubHelp logo

brenekh / logange Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 32 KB

Another Go logger library, tailored for my use case ๐Ÿคทโ€โ™€๏ธ

License: MIT License

Go 100.00%
logger logging go golang golang-library

logange's Introduction

Logange

GoDoc

Logging library which mimics Python's native logging library.

โš ๏ธ Logange is an experimental and non-production ready library. Use at your own risk.

Installation

Logange can be installed using the go get -u github.com/BrenekH/logange command.

Concepts

Logange uses loggers, formatters, and handlers.

Loggers are part of a family tree with logange.RootLogger as the base node. Logs will traverse the tree calling any attached handlers on the way to the root logger.

Handlers take log messages and send them to defined sources. There are two handlers already available as part of Logange, StdoutHandler and FileHandler which are instantiated using NewStdoutHandler and NewFileHandler respectively.

Formatters are used by handlers to add additional information to the logs.

Usage

Basic Setup

The following code creates a logger called main, defines how the message should be formatted, and uses the logange.StdoutHandler to output messages to the console.

package main

import "github.com/BrenekH/logange"

func main() {
    logger := logange.NewLogger("main")

    formatter := logange.StandardFormatter{FormatString: "${datetime}|${name}|${lineno}|${levelname}|${message}\n"}
    stdoutHandler := logange.NewStdoutHandler()

    stdoutHandler.SetFormatter(formatter)
    stdoutHandler.SetLevel(logange.LevelInfo)

    logger.AddHandler(&stdoutHandler)

    logger.Info("Hello, World!")
}

logange's People

Contributors

brenekh avatar

Stargazers

 avatar

Watchers

 avatar  avatar

logange's Issues

Double logging

Children loggers using created using Logger.NewLogger cause the log message to be outputted twice.

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.