log

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: MIT Imports: 6 Imported by: 5

README

Log

CI Go Report Card GoDoc


Log is a flexible logger for Golang applications. Inspired by xfxdev/xlog.

NOTICE Neither Fatal(f) nor Panic(f) functions exit the running code.

Installation

go get github.com/nszilard/log

Features

• Level logging

Support 7 different log levels, with an additional one having no level set. This makes it super easy to migrate from the built-in "log" package.

const (
	PanicLevel Level = iota
	FatalLevel
	ErrorLevel
	WarnLevel
	NoLevel
	InfoLevel
	TraceLevel
	DebugLevel
)
• Custom Log Layout

The layout can be modified according to the following table (you can use any combination):

Key Maps to Example
%y Year
%M Month
%d Day
%h Hours
%m Minutes
%s Seconds
%l Log message
%L Log level
%F File path /a/b/c/d.go
%f File name d.go
%i Line in file
%D %y/%M/%d
%T %h:%m:%s

NOTICE: If you doesn't call 'SetLayout', it will use %D %T %L (%f:%i) ▶ %l by default.

• Thread safety

Log is protected by a mutex, so you can output logs in multiple goroutines.

Documentation

Overview

Package log implements a simple logging package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

Debug is equivalent to Logger.Debug.

func Debugf

func Debugf(format string, v ...interface{})

Debugf is equivalent to Logger.Debugf.

func Error

func Error(v ...interface{})

Error is equivalent to Logger.Error.

func Errorf

func Errorf(format string, v ...interface{})

Errorf is equivalent to Logger.Errorf.

func Fatal

func Fatal(v ...interface{})

Fatal is equivalent to Logger.Fatal.

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf is equivalent to Logger.Fatalf.

func Info

func Info(v ...interface{})

Info is equivalent to Logger.Info.

func Infof

func Infof(format string, v ...interface{})

Infof is equivalent to Logger.Infof.

func New

func New(lev models.Level, listener io.Writer, layout string) *logger.Logger

New creates a new Logger.

func Panic

func Panic(v ...interface{})

Panic is equivalent to Logger.Panic.

func Panicf

func Panicf(format string, v ...interface{})

Panicf is equivalent to Logger.Panicf.

func Printf

func Printf(format string, v ...interface{})

Printf is equivalent to Logger.Logf.

func Println

func Println(v ...interface{})

Println is equivalent to Logger.Log.

func SetLevelDebug

func SetLevelDebug()

SetLevelDebug will set the log level to Debug

func SetLevelInfo

func SetLevelInfo()

SetLevelInfo will set the log level to Info

func SetOutput

func SetOutput(listener io.Writer)

SetOutput will set the output to the specified

func Trace

func Trace(v ...interface{})

Trace is equivalent to Logger.Debug.

func Tracef

func Tracef(format string, v ...interface{})

Tracef is equivalent to Logger.Debugf.

func Warn

func Warn(v ...interface{})

Warn is equivalent to Logger.Warn.

func Warnf

func Warnf(format string, v ...interface{})

Warnf is equivalent to Logger.Warnf.

Types

This section is empty.

Directories

Path Synopsis
Package internal hold the code that is not supposed to be accessible outside this package
Package internal hold the code that is not supposed to be accessible outside this package
pkg/layout
Package layout defines various layouts to use when formatting a log message
Package layout defines various layouts to use when formatting a log message
pkg/logger
Package logger provides the logging object
Package logger provides the logging object

Jump to

Keyboard shortcuts

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