BrenekH / logange

Another Go logger library, tailored for my use case 🤷‍♀️

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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!")
}

About

Another Go logger library, tailored for my use case 🤷‍♀️

License:MIT License


Languages

Language:Go 100.0%