logger

package
v4.2.2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: MIT Imports: 10 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}} - {{.Username}} [{{.Timestamp}}] [{{.Status}}] {{.Message}}"
	// DefaultRequestLoggingFormat defines the default request log format
	DefaultRequestLoggingFormat = "" /* 187-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
)

Variables

This section is empty.

Functions

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 GetClient

func GetClient(req *http.Request) string

GetClient parses an HTTP request for the client/remote IP address.

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 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 SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output destination for the standard logger.

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 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(calldepth int, message string)

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

func (*Logger) PrintAuth

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

PrintAuth 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) 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) 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