Documentation ¶
Overview ¶
Package golog Simple flexible go logging This file contains all the code for the main logger
Package golog Simple flexible go logging this file contains all the code for Info
Package golog Simple flexible go logging This file contains all un-exported (local) functions
Package golog Simple flexible go logging This file contains logger configuration implementation
Package golog Simple flexible go logging This file contains all code for the worker
Index ¶
- Constants
- func Stack() string
- type ColorMode
- type Environment
- type Info
- type LogLevel
- type Logger
- func (l *Logger) Critical(message string)
- func (l *Logger) CriticalE(err error)
- func (l *Logger) Criticalf(format string, a ...interface{})
- func (l *Logger) Debug(message string)
- func (l *Logger) DebugE(err error)
- func (l *Logger) Debugf(format string, a ...interface{})
- func (l *Logger) Error(message string)
- func (l *Logger) ErrorE(err error)
- func (l *Logger) Errorf(format string, a ...interface{})
- func (l *Logger) Fatal(message string)
- func (l *Logger) FatalE(err error)
- func (l *Logger) Fatalf(format string, a ...interface{})
- func (l *Logger) HandlerLog(w http.ResponseWriter, r *http.Request)
- func (l *Logger) HandlerLogf(w http.ResponseWriter, r *http.Request, format string, a ...interface{})
- func (l *Logger) Info(message string)
- func (l *Logger) Infof(format string, a ...interface{})
- func (l *Logger) Log(lvl LogLevel, message string)
- func (l *Logger) Notice(message string)
- func (l *Logger) Noticef(format string, a ...interface{})
- func (l *Logger) Panic(message string)
- func (l *Logger) PanicE(err error)
- func (l *Logger) Panicf(format string, a ...interface{})
- func (l *Logger) Print(message string)
- func (l *Logger) Printf(format string, a ...interface{})
- func (l *Logger) SetEnvironment(env Environment)
- func (l *Logger) SetFormat(format string)
- func (l *Logger) SetFunction(name string)
- func (l *Logger) SetLogLevel(level LogLevel)
- func (l *Logger) SetModuleName(name string)
- func (l *Logger) SetOutput(out io.Writer)
- func (l *Logger) StackAsCritical(message string)
- func (l *Logger) StackAsError(message string)
- func (l *Logger) Success(message string)
- func (l *Logger) Successf(format string, a ...interface{})
- func (l *Logger) Trace(name, file string, line int)
- func (l *Logger) UseJSONForProduction()
- func (l *Logger) Warning(message string)
- func (l *Logger) WarningE(err error)
- func (l *Logger) Warningf(format string, a ...interface{})
- type Options
- type Worker
- func (w *Worker) GetEnvironment() Environment
- func (w *Worker) Log(level LogLevel, calldepth int, info *Info)
- func (w *Worker) SetEnvironment(env Environment)
- func (w *Worker) SetFormat(format string)
- func (w *Worker) SetFunction(name string)
- func (w *Worker) SetLogLevel(level LogLevel)
- func (w *Worker) SetOutput(out io.Writer)
- func (w *Worker) UseJSONForProduction()
Constants ¶
const ( // FmtDefault is the default log format (QA) FmtDefault = "[%.16[3]s] #%[1]d %.19[2]s %.3[7]s %[8]s" // FmtProductionLog is the built-in production log format FmtProductionLog = "[%.16[3]s] %.19[2]s %.3[7]s - %[8]s" // FmtProductionJSON is the built-in production json format FmtProductionJSON = "{\"%.16[3]s\",\"%[5]s\",\"%[6]d\",\"%[4]s\",\"%[1]d\",\"%.19[2]s\",\"%[7]s\",\"%[8]s\"}" // FmtDevelopmentLog is the built-in development log format FmtDevelopmentLog = "[%.16[3]s] %.19[2]s %.3[7]s - %[5]s#%[6]d-%[4]s - %[8]s" )
const ( Black = (iota + 30) Red Green Yellow Blue Magenta Cyan White )
Color numbers for stdout
const ( RawLevel = iota + 1 // None CriticalLevel // Magneta 35 - Critical & Fatal Levels are same ErrorLevel // Red 31 WarningLevel // Yellow 33 SuccessLevel // Green 32 NoticeLevel // Cyan 36 InfoLevel // White 37 DebugLevel // Blue 34 )
Log Level. Panic is not included as a level.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Environment ¶
type Environment int
Environment enumeration
const ( // EnvNotSet - No Environment set (initial) EnvNotSet Environment = 0 + iota // EnvTesting - Internal, Used with `go test`, `goveralls`, ect EnvTesting // EnvDevelopment - All Log levels, color enabled and extra info on errors EnvDevelopment // EnvQuality - No debug level logging, color enabled, no extra info on errors EnvQuality // EnvProduction - Error level & higher, no color, minimum information EnvProduction )
type Info ¶
type Info struct { ID uint64 Time string Module string Function string Level LogLevel Line int Filename string Message string Duration time.Duration Method string StatusCode int Route string }
Info class, Contains all the info on what has to logged, time is the current time, Module is the specific module For which we are logging, level is the state, importance and type of message logged, Message contains the string to be logged, format is the format of string to be passed to sprintf
type Logger ¶
type Logger struct { Options Options // contains filtered or unexported fields }
Logger class that is an interface to user to log messages, Module is the module for which we are testing worker is variable of Worker class that is used in bottom layers to log the message
var ( // Log is set y the init function to be a default thelogger Log *Logger )
func NewLogger ¶
NewLogger creates and returns new logger for the given model & environment module is the specific module for which we are logging environment overrides detected environment (if -1) color defines whether the output is to be colored or not, out is instance of type io.Writer defaults to os.Stderr
func (*Logger) Criticalf ¶
Criticalf logs a message at Critical level using the same syntax and options as fmt.Printf
func (*Logger) Debugf ¶
Debugf logs a message at Debug level using the same syntax and options as fmt.Printf
func (*Logger) Errorf ¶
Errorf logs a message at Error level using the same syntax and options as fmt.Printf
func (*Logger) Fatal ¶
Fatal is just like func l.Critical logger except that it is followed by exit to program
func (*Logger) Fatalf ¶
Fatalf is just like func l.CriticalF logger except that it is followed by exit to program
func (*Logger) HandlerLog ¶
func (l *Logger) HandlerLog(w http.ResponseWriter, r *http.Request)
HandlerLog Traces & logs a message at Debug level for a REST handler
func (*Logger) HandlerLogf ¶
func (l *Logger) HandlerLogf(w http.ResponseWriter, r *http.Request, format string, a ...interface{})
HandlerLogf logs a message at Debug level using the same syntax and options as fmt.Printf
func (*Logger) Infof ¶
Infof logs a message at Info level using the same syntax and options as fmt.Printf
func (*Logger) Log ¶
Log The log command is the function available to user to log message, lvl specifies the degree of the message the user wants to log, message is the info user wants to log
func (*Logger) Noticef ¶
Noticef logs a message at Notice level using the same syntax and options as fmt.Printf
func (*Logger) Panic ¶
Panic is just like func l.Critical except that it is followed by a call to panic
func (*Logger) Panicf ¶
Panicf is just like func l.CriticalF except that it is followed by a call to panic
func (*Logger) Printf ¶
Printf logs a message at Info level using the same syntax and options as fmt.Printf
func (*Logger) SetEnvironment ¶
func (l *Logger) SetEnvironment(env Environment)
SetEnvironment is used to manually set the log environment to either development, testing or production
func (*Logger) SetFunction ¶
SetFunction sets the function name of the logger
func (*Logger) SetModuleName ¶
SetModuleName sets the name of the module being logged
func (*Logger) StackAsCritical ¶
StackAsCritical Prints this goroutine's execution stack as critical with an optional message at the begining
func (*Logger) StackAsError ¶
StackAsError Prints this goroutine's execution stack as an error with an optional message at the begining
func (*Logger) Successf ¶
Successf logs a message at Success level using the same syntax and options as fmt.Printf
func (*Logger) UseJSONForProduction ¶
func (l *Logger) UseJSONForProduction()
UseJSONForProduction forces using JSON instead of log for production
type Options ¶
type Options struct { Module string // Name of running module Environment Environment // Override default handling UseColor ColorMode // Enable color (override) default handling SmartError bool // Extended error that adapts by environment Out io.Writer // Where to write output FmtProd string // for use with production environment FmtDev string // for use with development environment }
Options allow customization of the logger by the end user
func NewCustomOptions ¶
func NewCustomOptions(module string, env Environment, clr ColorMode, SmartError bool, out io.Writer, fmtProd, fmtDev string) *Options
NewCustomOptions returns a new Options object with all user options
func NewDefaultOptions ¶
func NewDefaultOptions() *Options
NewDefaultOptions returns a new Options object with all defaults
func (*Options) EnvAsString ¶
EnvAsString returns the current envirnment for options as a string
type Worker ¶
Worker class, Worker is a log object used to log messages and Color specifies if colored output is to be produced
func NewWorker ¶
NewWorker Returns an instance of worker class, prefix is the string attached to every log, flag determine the log params, color parameters verifies whether we need colored outputs or not
func (*Worker) GetEnvironment ¶
func (w *Worker) GetEnvironment() Environment
GetEnvironment returns the currently set environment for the worker
func (*Worker) SetEnvironment ¶
func (w *Worker) SetEnvironment(env Environment)
SetEnvironment is used to manually set the log environment to either development, testing or production
func (*Worker) SetFunction ¶
SetFunction sets the function name ofr the worker
func (*Worker) UseJSONForProduction ¶
func (w *Worker) UseJSONForProduction()
UseJSONForProduction forces using JSON instead of log for production