log

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: MIT Imports: 3 Imported by: 7

README

Log

Log is a library which provides utilities for logging messages

Getting started

To retrieve the library, simply run:

go get code.waarp.fr/lib/log

Then import it in your project

import "code.waarp.fr/lib/log"

Basic Usage

In order to create a logger, its backend must first be initialized. Logging backends can be initialized using the NewBackend function. This function requires the following arguments:

  1. level- The minimum logging level. All messages bellow this level will be ignored.
  2. logTo- The logs output.
  3. facility- The logging facility (only used for syslog backends).
  4. tag- The application's tag in the logging facility (only used for syslog backends).

Once the backend initialized, loggers can be created using the Backend.NewLogger method. This will return a new logger with the given name, and which writes to the target backend.

License

Log is licensed under the terms of the MIT License which are detailed in the LICENSE file.

Documentation

Overview

Package log provides utilities for logging messages to various outputs.

Index

Constants

View Source
const (
	Stdout  = "stdout"
	Stderr  = "stderr"
	Discard = "discard"
	Syslog  = "syslog"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

func NewBackend

func NewBackend(level Level, logTo, facility, tag string) (*Backend, error)

NewBackend initializes the logging backend according to the given configuration. If the backend cannot be accessed, an error is returned.

Level represents the minimum logging priority accepted by the backend. Any message with a lower priority will be discarded.

LogTo is the logging output. It can be either: - Stdout - Stderr - Discard - Syslog - a file name

Facility and Tag are only used with a Syslog output. They represent respectively the logging facility and the application's name (in the logging facility).

func (*Backend) ChangeLevel

func (b *Backend) ChangeLevel(level Level)

func (*Backend) NewLogger

func (b *Backend) NewLogger(name string) *Logger

NewLogger initiates and returns a new logger with the target Backend as output.

type Level

type Level uint8

Level represents a logging level. Available levels are: - LevelDebug - LevelInfo - LevelWarning - LevelError - LevelCritical.

const (
	LevelTrace Level = iota + 1
	LevelDebug
	LevelInfo
	LevelNotice
	LevelWarning
	LevelError
	LevelCritical
	LevelAlert
	LevelFatal
)

func (Level) String

func (i Level) String() string

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is an internal abstraction of the underlying logging library.

func (*Logger) Alert

func (l *Logger) Alert(msg string, args ...any)

Alert outputs a log message at the "alert" (LevelAlert) priority.

func (*Logger) Critical

func (l *Logger) Critical(msg string, args ...any)

Critical outputs a log message at the "critical" (LevelCritical) priority.

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...any)

Debug outputs a log message at the "debug" (LevelDebug) priority.

func (*Logger) Error

func (l *Logger) Error(msg string, args ...any)

Error outputs a log message at the "error" (LevelError) priority.

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, args ...any)

Fatal outputs a log message at the "fatal" (LevelFatal) priority, and immediately exits the program afterwards.

func (*Logger) Info

func (l *Logger) Info(msg string, args ...any)

Info outputs a log message at the "info" (LevelInfo) priority.

func (*Logger) Notice

func (l *Logger) Notice(msg string, args ...any)

Notice outputs a log message at the "notice" (LevelNotice) priority.

func (*Logger) Trace

func (l *Logger) Trace(msg string, args ...any)

Trace outputs a log message at the "trace" (LevelTrace) priority.

func (*Logger) Warning

func (l *Logger) Warning(msg string, args ...any)

Warning outputs a log message at the "warning" (LevelWarning) priority.

Jump to

Keyboard shortcuts

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