logging

package
v2.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 9 Imported by: 17

Documentation

Overview

Package logging provides logging functionality for gnet server, it sets up a default logger (powered by go.uber.org/zap) which is about to be used by gnet server, it also allows users to replace the default logger with their customized logger by just implementing the `Logger` interface and assign it to the functional option `Options.Logger`, pass it to `gnet.Serve` method.

The environment variable `GNET_LOGGING_LEVEL` determines which zap logger level will be applied for logging. The environment variable `GNET_LOGGING_FILE` is set to a local file path when you want to print logs into local file. Alternatives of logging level (the variable of logging level ought to be integer):

const (

// DebugLevel logs are typically voluminous, and are usually disabled in
// production.
DebugLevel Level = iota - 1
// InfoLevel is the default logging priority.
InfoLevel
// WarnLevel logs are more important than Info, but don't need individual
// human review.
WarnLevel
// ErrorLevel logs are high-priority. If an application is running smoothly,
// it shouldn't generate any error-level logs.
ErrorLevel
// DPanicLevel logs are particularly important errors. In development the
// logger panics after writing the message.
DPanicLevel
// PanicLevel logs a message, then panics.
PanicLevel
// FatalLevel logs a message, then calls os.Exit(1).
FatalLevel

)

Index

Constants

View Source
const (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel = zapcore.DebugLevel
	// InfoLevel is the default logging priority.
	InfoLevel = zapcore.InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel = zapcore.WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel = zapcore.ErrorLevel
	// DPanicLevel logs are particularly important errors. In development the
	// logger panics after writing the message.
	DPanicLevel = zapcore.DPanicLevel
	// PanicLevel logs a message, then panics.
	PanicLevel = zapcore.PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel = zapcore.FatalLevel
)

Variables

This section is empty.

Functions

func Cleanup

func Cleanup()

Cleanup does something windup for logger, like closing, flushing, etc.

func Debugf

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

Debugf logs messages at DEBUG level.

func Error

func Error(err error)

Error prints err if it's not nil.

func Errorf

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

Errorf logs messages at ERROR level.

func Fatalf

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

Fatalf logs messages at FATAL level.

func Infof

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

Infof logs messages at INFO level.

func LogLevel

func LogLevel() string

LogLevel tells what the default logging level is.

func SetDefaultLoggerAndFlusher added in v2.2.9

func SetDefaultLoggerAndFlusher(logger Logger, flusher Flusher)

SetDefaultLoggerAndFlusher sets the default logger and its flusher.

func Warnf

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

Warnf logs messages at WARN level.

Types

type Flusher added in v2.2.9

type Flusher = func() error

Flusher is the callback function which flushes any buffered log entries to the underlying writer. It is usually called before the gnet process exits.

func GetDefaultFlusher added in v2.2.9

func GetDefaultFlusher() Flusher

GetDefaultFlusher returns the default flusher.

type Level

type Level = zapcore.Level

Level is the alias of zapcore.Level.

type Logger

type Logger interface {
	// Debugf logs messages at DEBUG level.
	Debugf(format string, args ...interface{})
	// Infof logs messages at INFO level.
	Infof(format string, args ...interface{})
	// Warnf logs messages at WARN level.
	Warnf(format string, args ...interface{})
	// Errorf logs messages at ERROR level.
	Errorf(format string, args ...interface{})
	// Fatalf logs messages at FATAL level.
	Fatalf(format string, args ...interface{})
}

Logger is used for logging formatted messages.

func CreateLoggerAsLocalFile

func CreateLoggerAsLocalFile(localFilePath string, logLevel Level) (logger Logger, flush func() error, err error)

CreateLoggerAsLocalFile setups the logger by local file path.

func GetDefaultLogger

func GetDefaultLogger() Logger

GetDefaultLogger returns the default logger.

Jump to

Keyboard shortcuts

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