Categorygithub.com/mef13/zslog
modulepackage
0.2.3
Repository: https://github.com/mef13/zslog.git
Documentation: pkg.go.dev

# README

zslog

Actions Status Go Report Card GitHub tag (latest SemVer) GitHub go.mod Go version Codecov GitHub

Simply configuring zerolog with output to console, lumberjack.v2, sentry-go, http.

Features

Example

package main

import (
    "github.com/mef13/zslog"
    "time"
)

func main() {
    fileConf := zslog.FileConfig{
        MaxSize:    1,
        MaxBackups: 10,
    }
    zslog.InitLogger(
        zslog.StdOut(zslog.NewLevels().SetMaxLevel(zslog.WarnLevel)),
        zslog.StdErr(zslog.NewLevels().SetMinLevel(zslog.ErrorLevel)),
        zslog.File("/var/log/myapp/err.log", fileConf, zslog.NewLevels().SetMinLevel(zslog.ErrorLevel)),
        zslog.Sentry(zslog.SentryConfig{
            Dsn:              "https://[email protected]/1",
            Release:          "0.0",
        }, 3*time.Second, zslog.NewLevels().SetMinLevel(zslog.ErrorLevel)))

    //Flush sentry buffer before exit
    defer zslog.Close()

    zslog.Info().Msg("hello world")
}

Set log level for output

Set specific levels:

zslog.StdOut(zslog.NewLevels(zslog.ErrorLevel, zslog.WarnLevel))

or set maximum(minimum) level:

zslog.StdOut(zslog.NewLevels().SetMaxLevel(zslog.WarnLevel))

Error Logging with Stacktrace

For add stacktrace use Stack() function:

package main

import (
	"github.com/mef13/zslog"
	"github.com/pkg/errors"
	"time"
)

func main() {
	zslog.InitLogger(
		zslog.Sentry(zslog.SentryConfig{
			Dsn:     "https://[email protected]/1",
			Release: "0.0",
		}, 3*time.Second, zslog.NewLevels().SetMinLevel(zslog.ErrorLevel)))

	//Flush sentry buffer before exit
	defer zslog.Close()

	err = outer()
	zslog.Error().Stack().Err(err).Msg("outer error")
}

func inner() error {
	return errors.New("Ah s*, here we go again")
}

func middle() error {
	err := inner()
	if err != nil {
		return err
	}
	return nil
}

func outer() error {
	err := middle()
	if err != nil {
		return err
	}
	return nil
}

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Sentry creates and return zerolog.LevelWriter interface.
No description provided by the author
SentryWithHub creates and return zerolog.LevelWriter interface.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

DebugLevel defines debug log level.
Disabled disables the logger.
ErrorLevel defines error log level.
FatalLevel defines fatal log level.
InfoLevel defines info log level.
NoLevel defines an absent log level.
PanicLevel defines panic log level.
TraceLevel defines trace log level.
WarnLevel defines warn log level.

# Variables

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author