πŸ“ πŸͺ΅ A minimal level based logging library for Go

Overview

slogx

Release Go License Code Size

A minimal level based logging library for Go.

Installation

go get github.com/IchBinLeoon/slogx

Example

package main

import "github.com/IchBinLeoon/slogx"

func main() {
    logger := slogx.NewLogger("EXAMPLE")

    logger.Error("This is Error!")
    logger.Errorf("This is %s!", "Error")

    logger.Warning("This is Warning!")
    logger.Warningf("This is %s!", "Warning")

    logger.Info("This is Info!")
    logger.Infof("This is %s!", "Info")
}

Output:

2021-06-08 20:08:19 ERROR main.go:11 EXAMPLE: This is Error!
2021-06-08 20:08:19 ERROR main.go:12 EXAMPLE: This is Error!
2021-06-08 20:08:19 WARNING main.go:14 EXAMPLE: This is Warning!
2021-06-08 20:08:19 WARNING main.go:15 EXAMPLE: This is Warning!
2021-06-08 20:08:19 INFO main.go:17 EXAMPLE: This is Info!
2021-06-08 20:08:19 INFO main.go:18 EXAMPLE: This is Info!

Usage

Logger

Create a new logger:

logger := slogx.NewLogger("awesome name")

Get an existing logger by its name:

logger := slogx.GetLogger("awesome name")

Log

Log a message at Fatal level and exit:

logger.Fatal("This is Fatal!")
logger.Fatalf("This is %s!", "Fatal")

Log a message at Error level:

logger.Error("This is Error!")
logger.Errorf("This is %s!", "Error")

Log a message at Warning level:

logger.Warning("This is Warning!")
logger.Warningf("This is %s!", "Warning")

Log a message at Info level:

logger.Info("This is Info!")
logger.Infof("This is %s!", "Info")

Log a message at Debug level:

logger.Debug("This is Debug!")
logger.Debugf("This is %s!", "Debug")

Log a message at a specified level:

logger.Log(slogx.ERROR, "This is Error!")
logger.Logf(slogx.INFO, "This is %s!", "Info")

Level

The default logging level is INFO.

Set the logging level:

logger.SetLevel(slogx.DEBUG)

Set the logging level from a string:

logger.SetLevel(slogx.ParseLevel("DEBUG"))

Get the current logging level:

level := logger.GetLevel()

Format

Set a custom format:

err := logger.SetFormat("[${time}] ${file} (${level}): ${message}")
if err != nil {
    // Handle error...
}
Verb Description
${time} The current time
${level} The logging level
${file} The file the log statement is in
${line} The line the log statement is on
${name} The name of the logger
${message} The log message

The default time format is 2006-01-02 15:04:05.

To change the time format:

logger.SetTimeFormat("Jan _2 15:04:05")

The time format must be a layout supported by the go time package.

Output

The default output is Stdout.

Set the output:

f, err := os.OpenFile("app.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
    // Handle error...
}
defer f.Close()

logger.SetOutput(f)

The output can be any io.Writer.

Contribute

Contributions are welcome! Feel free to open issues or submit pull requests!

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Releases(v1.0.0)
Owner
私はレγ‚ͺンです
School student and programmer from Germany who likes anime. I use Arch btw.
私はレγ‚ͺンです
Minimal structured logging library for Go

slog slog is a minimal structured logging library for Go. Install go get cdr.dev/slog Features Minimal API First class context.Context support First c

Coder 242 Jul 4, 2022
Gomol is a library for structured, multiple-output logging for Go with extensible logging outputs

gomol Gomol (Go Multi-Output Logger) is an MIT-licensed structured logging library for Go. Gomol grew from a desire to have a structured logging libra

Kristin Davidson 18 Dec 20, 2021
A simple logging module for go, with a rotating file feature and console logging.

A simple logging module for go, with a rotating file feature and console logging. Installation go get github.com/jbrodriguez/mlog Usage Sample usage W

Juan B. Rodriguez 25 Jun 11, 2022
FactorLog is a logging infrastructure for Go that provides numerous logging functions for whatever your style may be

FactorLog FactorLog is a fast logging infrastructure for Go that provides numerous logging functions for whatever your style may be. It could easily b

Kevin Darlington 54 Oct 12, 2021
Package logging implements a logging infrastructure for Go

Golang logging library Package logging implements a logging infrastructure for Go. Its output format is customizable and supports different logging ba

Luke Zhang 0 Nov 10, 2021
Simple and configurable Logging in Go, with level, formatters and writers

go-log Logging package similar to log4j for the Golang. Support dynamic log level Support customized formatter TextFormatter JSONFormatter Support mul

Guoqiang Chen 12 May 23, 2022
This package enables json output, level logging and so on to standard go logger.

logplug This package enables json output, level logging and so on to standard logger. Usage log.SetOutput(logplug.NewJSONPlug(os.Stderr, logplug.LogF

Koumei Mikuni 0 Dec 27, 2021
Multi-level logger based on go std log

mlog the mlog is multi-level logger based on go std log. It is: Simple Easy to use NOTHING ELSE package main import ( log "github.com/ccpaging/lo

null 0 May 18, 2022
Simple and blazing fast lockfree logging library for golang

glg is simple golang logging library Requirement Go 1.11 Installation go get github.com/kpango/glg Example package main import ( "net/http" "time"

Yusuke Kato 161 Jul 2, 2022
Logging library for Golang

GLO Logging library for Golang Inspired by Monolog for PHP, severity levels are identical Install go get github.com/lajosbencz/glo Severity levels Deb

Lajos Bencz 14 Aug 26, 2021
The Simplest and worst logging library ever written

gologger A Simple Easy to use go logger library. Displays Colored log into console in any unix or windows platform. You can even store your logs in fi

Sadlil Rhythom 41 Jun 22, 2022
Minimalistic logging library for Go.

logger Minimalistic logging library for Go. Blog Post Features: Advanced output filters (package and/or level) Attributes Timers for measuring perform

Azer Koçulu 153 Jun 29, 2022
Seelog is a native Go logging library that provides flexible asynchronous dispatching, filtering, and formatting.

Seelog Seelog is a powerful and easy-to-learn logging framework that provides functionality for flexible dispatching, filtering, and formatting log me

Seelog project repository 1.6k Jun 30, 2022
A pure Go contextual logging library with "batteries included"

Cue Overview Cue implements contextual logging with "batteries included". It has thorough test coverage and supports logging to stdout/stderr, file, s

Bob Ziuchkovski 26 Sep 16, 2019
Golang logging library

Golang logging library Package logging implements a logging infrastructure for Go. Its output format is customizable and supports different logging ba

Γ–rjan Fors 1.8k Jun 23, 2022
Hierarchical, leveled, and structured logging library for Go

spacelog Please see http://godoc.org/github.com/spacemonkeygo/spacelog for info License Copyright (C) 2014 Space Monkey, Inc. Licensed under the Apach

Space Monkey Go 98 Apr 27, 2021
GoVector is a vector clock logging library written in Go.

GoVector is a vector clock logging library written in Go. The vector clock algorithm is used to order events in distributed systems in the absence of a centralized clock. GoVector implements the vector clock algorithm and provides feature-rich logging and encoding infrastructure.

Distributed clocks 163 Jun 18, 2022
Parametrized JSON logging library in Golang which lets you obfuscate sensitive data and marshal any kind of content.

Noodlog Summary Noodlog is a Golang JSON parametrized and highly configurable logging library. It allows you to: print go structs as JSON messages; pr

Gyoza Tech 37 Apr 19, 2022
Cloud logging library in golang

?? logg Open Source Cloud logging library in Go. About the project Connect your golang microservices logs with this engine! Send your logs to kafka, r

yuri 3 Nov 8, 2021