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

Write to stdout/stderr and create a rotating logfile

package main

import "github.com/jbrodriguez/mlog"

func main() {
	mlog.Start(mlog.LevelInfo, "app.log")

	mlog.Info("Hello World !")

	ipsum := "ipsum"
	mlog.Warning("Lorem %s", ipsum)
}

Write to stdout/stderr only

package main

import "github.com/jbrodriguez/mlog"

func main() {
	mlog.Start(mlog.LevelInfo, "")

	mlog.Info("Hello World !")

	ipsum := "ipsum"
	mlog.Warning("Lorem %s", ipsum)
}

By default, the log will be rolled over to a backup file when its size reaches 10Mb and 10 such files will be created (and eventually reused).

Alternatively, you can specify the max size of the log file before it gets rotated, and the number of backup files you want to create, with the StartEx function.

package main

import "github.com/jbrodriguez/mlog"

func main() {
    mlog.StartEx(mlog.LevelInfo, "app.log", 5*1024*1024, 5)

    mlog.Info("Hello World !")

    ipsum := "ipsum"
    mlog.Warning("Lorem %s", ipsum)
}

This will rotate the file when it reaches 5Mb and 5 backup files will eventually be created.

Setting logger flags:

mlog.DefaultFlags = log.Ldate|log.Ltime|log.Lmicroseconds|log.Lshortfile

Output

I: 2015/05/15 07:09:45 main.go:10: Hello World !
W: 2015/05/15 07:09:45 main.go:13: Lorem ipsum
Owner
Similar Resources

Very powerful server agent for collecting & sending logs & metrics with an easy-to-use web console.

Very powerful server agent for collecting & sending logs & metrics with an easy-to-use web console.

logkit-community δΈ­ζ–‡η‰ˆ Introduce Very powerful server agent for collecting & sending logs & metrics with an easy-to-use web console. logkit-community De

Dec 29, 2022

Sugared logger for console with request id

Sugared logger for console with request id

πŸ“ zlog You don't know what it's like, you don't have a clue If you did you'd find yourselves doing the same thing too Sugared logger for console with

Sep 24, 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

Sep 26, 2022

Simple and blazing fast lockfree logging library for golang

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"

Nov 28, 2022

Simple, configurable and scalable Structured Logging for Go.

log Log is a simple, highly configurable, Structured Logging library Why another logging library? There's allot of great stuff out there, but also tho

Sep 26, 2022

Simple, customizable, leveled and efficient logging in Go

log Simple, customizable, leveled and efficient logging in Go Installation go get -u github.com/ermanimer/log Features log is a simple logging package

Dec 20, 2021

Parse awesome-go README file and generate a new README file with repo info.

Awesome Go Extra All data are from awesome-go and GitHub API. Audio and Music Libraries for manipulating audio. Name Description Star Open Issues Crea

Aug 11, 2022

A simple logging interface for Go

A more minimal logging API for Go Before you consider this package, please read this blog post by the inimitable Dave Cheney. I really appreciate what

Dec 30, 2022

A simple logging framework for Go program.

A simple logging framework for Go program.

ASLP A Go language based log library, simple, convenient and concise. Three modes, standard output, file mode and common mode. Convenient, simple and

Nov 14, 2022
Comments
  • License?

    License?

    Hello, I was wondering if a License could be added so I can use this in my own projects. If you need some help on choosing a License please visit TL;DR Legal here.

    Thanks.

  • how to change outLine  format

    how to change outLine format

    how to change out format:

    I: 2019/07/13 22:51:08 log.go:12: ---start-----
    

    i want change it to

    2019/07/13 22:51:08 [INFO]  log.go:12: ---start-----
    

    like webServer log

Rotating File Writer

Rotating File writer An io.writer & io.Closer compliant file writer that will always write to the path that you give it, even if somebody deletes/rena

Jul 12, 2021
Tiny structured logging abstraction or facade for various logging libraries, allowing the end user to plug in the desired logging library in main.go
Tiny structured logging abstraction or facade for various logging libraries, allowing the end user to plug in the desired logging library in main.go

Tiny structured logging abstraction or facade for various logging libraries, allowing the end user to plug in the desired logging library in main.go.

Dec 7, 2022
A reusable logger module for basic logging, written in Go
A reusable logger module for basic logging, written in Go

logger A reusable logger module for basic logging, written in Go. Usage Client p

Jan 8, 2022
πŸͺ΅ A dead simple, pretty, and feature-rich logger for golang
πŸͺ΅ A dead simple, pretty, and feature-rich logger for golang

?? lumber ?? A dead simple, pretty, and feature-rich logger for golang ?? Install ?? Logging Functions lumber.Success() lumber.Info() lumber.Debug() l

Jul 20, 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

Sep 26, 2022
FactorLog is a logging infrastructure for Go that provides numerous logging functions for whatever your style may be
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

Aug 3, 2022
Package logging implements a logging infrastructure for Go
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

Nov 10, 2021
A simple digital clock written in go to show time in hh : mm : ss format in console

Go console clock a simple digital clock written in go to show time in "hh : mm :

Feb 3, 2022
A feature-rich and easy to use logger for golang
A feature-rich and easy to use logger for golang

A feature-rich and easy to use logger for golang ?? Install ?? Common Logs lumber.Success() lumber.Info() lumber.Debug() lumber.Warning()

Dec 31, 2022
Clean architecture starter pack for faster and easier feature creation using Go.
Clean architecture starter pack for faster and easier feature creation using Go.

cleanarchGo ?? About Clean architecture starter pack for faster and easier feature creation using Go. This pack includes Clean Architecture with the E

May 8, 2023