gologutils

package module
v0.0.0-...-920288f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2022 License: MIT Imports: 4 Imported by: 0

README

gologutils

Golang logging helper to quickly start project with zerolog

import module

go get -u github.com/tgrangeray/gologutils

usage with file and console

import (
	"github.com/tgrangeray/gologutils"
)

func main() {

    debug := flag.Bool("debug", false, "sets log level to debug")

	gologutils.InitLog(*debug, true, &gologutils.LogFileConfig{
		Filename: "myapp.log",
	})
	defer gologutils.RootLogger.Close()

    // obtain a zerolog logger without component name
	logger := gologutils.RootLogger.NewLogger("")
	logger.Info().Msg("starting")

    // obtain a zerolog logger with component name
	logger := gologutils.RootLogger.NewLogger("main")
	logger.Info().Msg("starting with component 'main'")
}

usage without file (just console)

func main() {

	gologutils.InitLog(*debug, true, nil)
	defer gologutils.RootLogger.Close()

}

usage with file, without console (production mode)

func main() {

	gologutils.InitLog(*debug, false, &gologutils.LogFileConfig{
		Filename: "myapp.log",
	})

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLog

func InitLog(debug bool, console bool, logFileConfig *LogFileConfig)

Types

type LogFileConfig

type LogFileConfig struct {
	Filename     string
	MaxSizeMB    int
	MaxBackups   int
	MaxAgeInDays int
}

type Logging

type Logging struct {
	// contains filtered or unexported fields
}
var RootLogger Logging

func (*Logging) Close

func (l *Logging) Close()

Close ...

func (*Logging) NewLogger

func (l *Logging) NewLogger(componentName string) *zerolog.Logger

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL