logger

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: MIT Imports: 6 Imported by: 0

README

Golang logger package

godoc pipeline status coverage report Go Report Card GoLang Version

Package logging implements a logging infrastructure for Go. Its output format is customizable.

Example

Default
package main

import (
	"git.pingcode.io/go-packages/logger"
)

func main() {
    logger.Default("Default")
    logger.Defaultf("%s", "Defaultf")
    
    logger.Debug("Debug")
    logger.Debugf("%s", "Debugf")
    
    logger.Info("Info")
    logger.Infof("%s", "Infof")
    
    logger.Notice("Notice")
    logger.Noticef("%s", "Noticef")
    
    logger.Warning("Warning")
    logger.Warningf("%s", "Warningf")
    
    logger.Error("Error")
    logger.Errorf("%s", "Errorf")
    
    logger.Critical("Critical")
    logger.Criticalf("%s", "Criticalf")
    
    logger.Alert("Alert")
    logger.Alertf("%s", "Alertf")
    
    logger.Emergency("Emergency")
    logger.Emergencyf("%s", "Emergencyf")
}
Basic
package main

import (
	"git.pingcode.io/go-packages/logger"
)

func main() {
    l := logger.New()
    
    l.SetFormat("%{color}%{severity:substring(0:4)}[%{datetime}] %{hostname} =>%{reset} %{message}")
    l.Options.DisableColor()
    
    l.Default("Default")
    l.Defaultf("%s", "Defaultf")
    
    l.Debug("Debug")
    l.Debugf("%s", "Debugf")
    
    l.Info("Info")
    l.Infof("%s", "Infof")
    
    l.Notice("Notice")
    l.Noticef("%s", "Noticef")
    
    l.Warning("Warning")
    l.Warningf("%s", "Warningf")
    
    l.Error("Error")
    l.Errorf("%s", "Errorf")
    
    l.Critical("Critical")
    l.Criticalf("%s", "Criticalf")
    
    l.Alert("Alert")
    l.Alertf("%s", "Alertf")
    
    l.Emergency("Emergency")
    l.Emergencyf("%s", "Emergencyf")
}

Installing

$ go get git.pingcode.io/go-packages/logger

Usage

Functions available
Name Description Usage
code Print severity code %{code}
severity Print severity name %{severity}
color Enable color line %{color}
reset Reset color to default %{reset}
datetime Print datetime in format RFC3339 %{datetime}
hostname Print hostname %{hostname}
message Print message %{message}
stackdriver Print message in json stackdriver format %{stackdriver}
Filters available
Name Description Usage
substrings, substring Extracts the characters from a string %{severity:substring(0:4)}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alert

func Alert(args ...interface{})

Alert logs a message at level Alert on the standard logger.

func Alertf

func Alertf(format string, args ...interface{})

Alertf logs a message at level Alert on the standard logger.

func Critical

func Critical(args ...interface{})

Critical logs a message at level Critical on the standard logger.

func Criticalf

func Criticalf(format string, args ...interface{})

Criticalf logs a message at level Critical on the standard logger.

func Debug

func Debug(args ...interface{})

Debug logs a message at level Debug on the standard logger.

func Debugf

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

Debugf logs a message at level Debug on the standard logger.

func Default

func Default(args ...interface{})

Default logs a message at level Default on the standard logger.

func Defaultf

func Defaultf(format string, args ...interface{})

Defaultf logs a message at level Default on the standard logger.

func Emergency

func Emergency(args ...interface{})

Emergency logs a message at level Emergency on the standard logger.

func Emergencyf

func Emergencyf(format string, args ...interface{})

Emergencyf logs a message at level Emergency on the standard logger.

func Error

func Error(args ...interface{})

Error logs a message at level Error on the standard logger.

func Errorf

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

Errorf logs a message at level Error on the standard logger.

func Info

func Info(args ...interface{})

Info logs a message at level Info on the standard logger.

func Infof

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

Infof logs a message at level Info on the standard logger.

func Notice

func Notice(args ...interface{})

Notice logs a message at level Notice on the standard logger.

func Noticef

func Noticef(format string, args ...interface{})

Noticef logs a message at level Notice on the standard logger.

func Warning

func Warning(args ...interface{})

Warning logs a message at level Warning on the standard logger.

func Warningf

func Warningf(format string, args ...interface{})

Warningf logs a message at level Warning on the standard logger.

Types

type Logger

type Logger struct {
	Options src.Options
	// contains filtered or unexported fields
}

Logger is configuration

func New

func New() *Logger

func (*Logger) Alert

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

Alert logs a message at level Alert on the custom logger.

func (*Logger) Alertf

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

Alertf logs a message at level Alert on the custom logger.

func (*Logger) Critical

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

Critical logs a message at level Critical on the custom logger.

func (*Logger) Criticalf

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

Criticalf logs a message at level Critical on the custom logger.

func (*Logger) Debug

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

Debug logs a message at level Debug on the custom logger.

func (*Logger) Debugf

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

Debugf logs a message at level Debug on the custom logger.

func (*Logger) Default

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

Default logs a message at level Default on the custom logger.

func (*Logger) Defaultf

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

Defaultf logs a message at level Default on the custom logger.

func (*Logger) Emergency

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

Emergency logs a message at level Emergency on the custom logger.

func (*Logger) Emergencyf

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

Emergencyf logs a message at level Emergency on the custom logger.

func (*Logger) Error

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

Error logs a message at level Error on the custom logger.

func (*Logger) Errorf

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

Errorf logs a message at level Error on the custom logger.

func (*Logger) Info

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

Info logs a message at level Info on the custom logger.

func (*Logger) Infof

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

Infof logs a message at level Info on the custom logger.

func (*Logger) Notice

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

Notice logs a message at level Notice on the custom logger.

func (*Logger) Noticef

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

Noticef logs a message at level Notice on the custom logger.

func (*Logger) SetFormat

func (l *Logger) SetFormat(format string) *Logger

SetFormat set logger format output

func (*Logger) SetLevel

func (l *Logger) SetLevel(level string) (*Logger, error)

SetLevel set level view

func (*Logger) SetOutput

func (l *Logger) SetOutput(output io.Writer) *Logger

SetOutput set global output

func (*Logger) Warning

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

Warning logs a message at level Warning on the custom logger.

func (*Logger) Warningf

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

Warningf logs a message at level Warning on the custom logger.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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