Help us shape the future of Go! Take the 2026 Go Developer Survey

log

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 13 Imported by: 201

README

ion-log

QuickStart

package main

import (
	log "github.com/pion/ion-log"
)

func init() {
	log.Init("debug")
}

func main() {
	log.Infof("Hello ION!")
}

Feature

GoodFormat:

[date time]  [Level] [Prefix]: [file:line] [Func] YourLog fields=value
[2021-05-06 09:54:49.658]  INFO default: [log_test.go:19] [ion-log_test.TestDefaultLogger] log with format ION somefield=foo

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debugf

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

Debugf logs a formatted debug level log to the console

func Errorf

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

Errorf logs a formatted error level log to the console

func GetLoggers added in v1.2.0

func GetLoggers() map[string]*MyLogger

func Infof

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

Infof logs a formatted info level log to the console

func Init

func Init(level string)

func NewLogger added in v1.2.0

func NewLogger(level Level, prefix string) *logrus.Logger

func NewLoggerWithFields added in v1.2.0

func NewLoggerWithFields(level Level, prefix string, fields Fields) *logrus.Logger

func Panicf

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

Panicf logs a formatted panic level log to the console. The panic() function is called, which stops the ordinary flow of a goroutine.

func SetLogLevel added in v1.2.0

func SetLogLevel(prefix string, level Level) error

func Tracef

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

Tracef logs a formatted debug level log to the console

func Warnf

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

Warnf logs a formatted warn level log to the console

Types

type ColorScheme added in v1.2.0

type ColorScheme struct {
	InfoLevelStyle  string
	WarnLevelStyle  string
	ErrorLevelStyle string
	FatalLevelStyle string
	PanicLevelStyle string
	DebugLevelStyle string
	PrefixStyle     string
	TimestampStyle  string
}

type Fields added in v1.2.0

type Fields map[string]interface{}

type Level added in v1.2.0

type Level uint32

Level type

const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel Level = iota
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel
)

These are the different logging levels. You can set the logging level to log on your instance of logger, obtained with `logrus.New()`.

func StringToLevel added in v1.2.1

func StringToLevel(level string) Level

type MyLogger added in v1.2.0

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

func (*MyLogger) Level added in v1.2.0

func (ml *MyLogger) Level() string

func (*MyLogger) Prefix added in v1.2.0

func (ml *MyLogger) Prefix() string

func (*MyLogger) SetLevel added in v1.2.0

func (ml *MyLogger) SetLevel(level Level)

type TextFormatter added in v1.2.0

type TextFormatter struct {
	Prefix string

	Fields Fields

	// Set to true to bypass checking for a TTY before outputting colors.
	ForceColors bool

	// Force disabling colors. For a TTY colors are enabled by default.
	DisableColors bool

	// Force formatted layout, even for non-TTY output.
	ForceFormatting bool

	// Disable timestamp logging. useful when output is redirected to logging
	// system that already adds timestamps.
	DisableTimestamp bool

	// Disable the conversion of the log levels to uppercase
	DisableUppercase bool

	// Enable logging the full timestamp when a TTY is attached instead of just
	// the time passed since beginning of execution.
	FullTimestamp bool

	// Timestamp format to use for display when a full timestamp is printed.
	TimestampFormat string

	// The fields are sorted by default for a consistent output. For applications
	// that log extremely frequently and don't use the JSON formatter this may not
	// be desired.
	DisableSorting bool

	// Wrap empty fields in quotes if true.
	QuoteEmptyFields bool

	// Can be set to the override the default quoting character "
	// with something else. For example: ', or `.
	QuoteCharacter string

	// Pad msg field with spaces on the right for display.
	// The value for this parameter will be the size of padding.
	// Its default value is zero, which means no padding will be applied for msg.
	SpacePadding int

	sync.Once
	// contains filtered or unexported fields
}

func (*TextFormatter) Format added in v1.2.0

func (f *TextFormatter) Format(entry *logrus.Entry) ([]byte, error)

func (*TextFormatter) SetColorScheme added in v1.2.0

func (f *TextFormatter) SetColorScheme(colorScheme *ColorScheme)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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