logger

package
v7.0.0-...-1c7ecba Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultStandardLoggingFormat defines the default standard log format
	DefaultStandardLoggingFormat = "[{{.Timestamp}}] [{{.File}}] {{.Message}}"
	// DefaultAuthLoggingFormat defines the default auth log format
	DefaultAuthLoggingFormat = "{{.Client}} - {{.RequestID}} - {{.Username}} [{{.Timestamp}}] [{{.Status}}] {{.Message}}"
	// DefaultRequestLoggingFormat defines the default request log format
	DefaultRequestLoggingFormat = "" /* 204-byte string literal not displayed */

	// AuthSuccess indicates that an auth attempt has succeeded explicitly
	AuthSuccess AuthStatus = "AuthSuccess"
	// AuthFailure indicates that an auth attempt has failed explicitly
	AuthFailure AuthStatus = "AuthFailure"
	// AuthError indicates that an auth attempt has failed due to an error
	AuthError AuthStatus = "AuthError"

	// Llongfile flag to log full file name and line number: /a/b/c/d.go:23
	Llongfile = 1 << iota
	// Lshortfile flag to log final file name element and line number: d.go:23. overrides Llongfile
	Lshortfile
	// LUTC flag to log UTC datetime rather than the local time zone
	LUTC
	// LstdFlags flag for initial values for the logger
	LstdFlags = Lshortfile

	// DEFAULT is the default log level (effectively INFO)
	DEFAULT Level = iota
	// ERROR is for error-level logging
	ERROR
)

Variables

This section is empty.

Functions

func Error

func Error(v ...interface{})

Error calls OutputErr to print to the standard logger's error channel. Arguments are handled in the manner of fmt.Print.

func Errorf

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

Errorf calls OutputErr to print to the standard logger's error channel. Arguments are handled in the manner of fmt.Printf.

func Errorln

func Errorln(v ...interface{})

Errorln calls OutputErr to print to the standard logger's error channel. Arguments are handled in the manner of fmt.Println.

func Fatal

func Fatal(v ...interface{})

Fatal is equivalent to Print() followed by a call to os.Exit(1).

func Fatalf

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

Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

func Fatalln

func Fatalln(v ...interface{})

Fatalln is equivalent to Println() followed by a call to os.Exit(1).

func Flags

func Flags() int

Flags returns the output flags for the standard logger.

func FormatTimestamp

func FormatTimestamp(ts time.Time) string

FormatTimestamp returns a formatted timestamp for the standard logger.

func Panic

func Panic(v ...interface{})

Panic is equivalent to Print() followed by a call to panic().

func Panicf

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

Panicf is equivalent to Printf() followed by a call to panic().

func Panicln

func Panicln(v ...interface{})

Panicln is equivalent to Println() followed by a call to panic().

func Print

func Print(v ...interface{})

Print calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Print.

func PrintAuthf

func PrintAuthf(username string, req *http.Request, status AuthStatus, format string, a ...interface{})

PrintAuthf writes authentication details to the standard logger. Arguments are handled in the manner of fmt.Printf.

func PrintReq

func PrintReq(username, upstream string, req *http.Request, url url.URL, ts time.Time, status int, size int)

PrintReq writes request details to the standard logger.

func Printf

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

Printf calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Printf.

func Println

func Println(v ...interface{})

Println calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Println.

func SetAuthEnabled

func SetAuthEnabled(e bool)

SetAuthEnabled enables or disables auth logging for the standard logger.

func SetAuthTemplate

func SetAuthTemplate(t string)

SetAuthTemplate sets the template for auth logging for the standard logger.

func SetErrOutput

func SetErrOutput(w io.Writer)

SetErrOutput sets the output destination for the standard logger's error channel.

func SetErrToInfo

func SetErrToInfo(e bool)

SetErrToInfo enables or disables error logging to output writer instead of error writer.

func SetExcludePaths

func SetExcludePaths(s []string)

SetExcludePaths sets the path to exclude from logging, eg: health checks

func SetFlags

func SetFlags(flag int)

SetFlags sets the output flags for the standard logger.

func SetGetClientFunc

func SetGetClientFunc(f GetClientFunc)

SetGetClientFunc sets the function which determines the apparent IP address set by a reverse proxy for the standard logger.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output destination for the standard logger's default channel.

func SetReqEnabled

func SetReqEnabled(e bool)

SetReqEnabled enables or disables request logging for the standard logger.

func SetReqTemplate

func SetReqTemplate(t string)

SetReqTemplate sets the template for request logging for the standard logger.

func SetStandardEnabled

func SetStandardEnabled(e bool)

SetStandardEnabled enables or disables standard logging for the standard logger.

func SetStandardTemplate

func SetStandardTemplate(t string)

SetStandardTemplate sets the template for standard logging for the standard logger.

Types

type AuthStatus

type AuthStatus string

AuthStatus defines the different types of auth logging that occur

type GetClientFunc

type GetClientFunc = func(r *http.Request) string

Returns the apparent "real client IP" as a string.

type Level

type Level int

Level indicates the log level for log messages

type Logger

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

A Logger represents an active logging object that generates lines of output to an io.Writer passed through a formatter. Each logging operation makes a single call to the Writer's Write method. A Logger can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer.

func New

func New(flag int) *Logger

New creates a new Standarderr Logger.

func (*Logger) Flags

func (l *Logger) Flags() int

Flags returns the output flags for the logger.

func (*Logger) FormatTimestamp

func (l *Logger) FormatTimestamp(ts time.Time) string

FormatTimestamp returns a formatted timestamp.

func (*Logger) GetFileLineString

func (l *Logger) GetFileLineString(calldepth int) string

GetFileLineString will find the caller file and line number taking in to account the calldepth to iterate up the stack to find the non-logging call location.

func (*Logger) Output

func (l *Logger) Output(lvl Level, calldepth int, message string)

Output a standard log template with a simple message to default output channel. Write a final newline at the end of every message.

func (*Logger) PrintAuthf

func (l *Logger) PrintAuthf(username string, req *http.Request, status AuthStatus, format string, a ...interface{})

PrintAuthf writes auth info to the logger. Requires an http.Request to log request details. Remaining arguments are handled in the manner of fmt.Sprintf. Writes a final newline to the end of every message.

func (*Logger) PrintReq

func (l *Logger) PrintReq(username, upstream string, req *http.Request, url url.URL, ts time.Time, status int, size int)

PrintReq writes request details to the Logger using the http.Request, url, and timestamp of the request. Writes a final newline to the end of every message.

func (*Logger) SetAuthEnabled

func (l *Logger) SetAuthEnabled(e bool)

SetAuthEnabled enables or disables auth logging.

func (*Logger) SetAuthTemplate

func (l *Logger) SetAuthTemplate(t string)

SetAuthTemplate sets the template for auth logging.

func (*Logger) SetErrToInfo

func (l *Logger) SetErrToInfo(e bool)

SetErrToInfo enables or disables error logging to error writer instead of the default.

func (*Logger) SetExcludePaths

func (l *Logger) SetExcludePaths(s []string)

SetExcludePaths sets the paths to exclude from logging.

func (*Logger) SetFlags

func (l *Logger) SetFlags(flag int)

SetFlags sets the output flags for the logger.

func (*Logger) SetGetClientFunc

func (l *Logger) SetGetClientFunc(f GetClientFunc)

SetGetClientFunc sets the function which determines the apparent "real client IP".

func (*Logger) SetReqEnabled

func (l *Logger) SetReqEnabled(e bool)

SetReqEnabled enabled or disables request logging.

func (*Logger) SetReqTemplate

func (l *Logger) SetReqTemplate(t string)

SetReqTemplate sets the template for request logging.

func (*Logger) SetStandardEnabled

func (l *Logger) SetStandardEnabled(e bool)

SetStandardEnabled enables or disables standard logging.

func (*Logger) SetStandardTemplate

func (l *Logger) SetStandardTemplate(t string)

SetStandardTemplate sets the template for standard logging.

Jump to

Keyboard shortcuts

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