log

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2021 License: MIT Imports: 9 Imported by: 0

README

log

Simple logging library with functionality for enabling and disabling log levels at runtime. A separate instance of Logger is intended for each package that emit log messages. That way FATAL, ERROR, WARNING, INFO and DEBUG log messages can be enabled and disable for the specific packages.

log's API is not yet stable.

Documentation

Overview

Package log implements logging package with runtime support for enabling and disabling log levels.

Example (Basic)
package main

import (
	"fmt"

	"ngrd.no/log"
)

func main() {
	logger, err := log.New(log.WithDisabledTimestamp())
	if err != nil {
		fmt.Printf("Error: %v\n", err)
	}
	logger.Infof("Hello")
	logger.Warnf("This is a warning")
	logger.Debugf("This is not logged by default")

}
Output:
	ngrd.no/log_test	INFO	Hello
	ngrd.no/log_test	WARN	This is a warning

Index

Examples

Constants

View Source
const (
	FATAL control.Level = iota + 1
	ERROR
	WARNING
	INFO
	DEBUG

	UNKNOWN = -1
)

Variables

View Source
var (
	ApplicationName string
	GlobalOptions   []Option
)

Functions

func LevelStringToType

func LevelStringToType(level string) control.Level

Types

type Logger

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

func New

func New(options ...Option) (*Logger, error)

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

func (*Logger) Fatalln

func (l *Logger) Fatalln(args ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

func (*Logger) Log

func (l *Logger) Log(level control.Level, msg string)

func (*Logger) Print

func (l *Logger) Print(args ...interface{})

func (*Logger) Printf

func (l *Logger) Printf(format string, args ...interface{})

func (*Logger) Println

func (l *Logger) Println(args ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

type Option

type Option func(l *Logger)

Option sets option when a new logger is created

func WithComponentName

func WithComponentName(component string) Option

WithComponentName overrides the default component name for a Logger instance

func WithDisabledTimestamp

func WithDisabledTimestamp() Option

WithDisabledTimestamp removes the timestamp from the log message

func WithLogControl

func WithLogControl(c *control.LogControl) Option

WithLogControl overrides the default LogControl instance used

func WithTimeLayout

func WithTimeLayout(layout string) Option

WithTimeFormat sets how the logger should represent the time pf a log message using (t time.Time) Format(layout string).

func WithTimeUnixNano

func WithTimeUnixNano() Option

WithTimeUnixNano represents the time of a log message as nanoseconds since unix epoch.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter sets a specific writer as the log message sink

Directories

Path Synopsis
cmd
logctl command
Package control implements necessary functionality for runtime level toggling.
Package control implements necessary functionality for runtime level toggling.
mmap
Package mmap implements functionality for keeping a files data in memory.
Package mmap implements functionality for keeping a files data in memory.

Jump to

Keyboard shortcuts

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