Documentation ¶
Index ¶
- Constants
- Variables
- func Configure(l *LogConfig)
- type BaseLogger
- func (l *BaseLogger) Debug(a ...interface{})
- func (l *BaseLogger) DebugF(f string, a ...interface{})
- func (l *BaseLogger) Error(a ...interface{})
- func (l *BaseLogger) ErrorF(f string, a ...interface{})
- func (l *BaseLogger) Info(a ...interface{})
- func (l *BaseLogger) InfoF(f string, a ...interface{})
- func (l *BaseLogger) IsEnabled(sev Level) bool
- func (l *BaseLogger) Trace(a ...interface{})
- func (l *BaseLogger) TraceF(f string, a ...interface{})
- func (l *BaseLogger) Warn(a ...interface{})
- func (l *BaseLogger) WarnF(f string, a ...interface{})
- type ConsoleConfig
- type ConsoleWriter
- type FileConfig
- type FileWriter
- type Level
- type LogConfig
- type LogMessage
- type LogWriter
- type Logger
- type PackageConfig
- type WriterConfig
Constants ¶
const ( // LogConfigEnvProperty specifies the environment variable that would specify the file location LogConfigEnvProperty = "GC_LOG_CONFIG_FILE" //DefaultlogFilePath specifies the location where the application should search for log config if the LogConfigEnvProperty is not specified DefaultlogFilePath = "./log-config.json" )
Variables ¶
var Levels = [...]string{
"OFF",
"ERROR",
"WARN",
"INFO",
"DEBUG",
"TRACE",
}
Levels of the logging by severity
var LevelsBytes = [...][]byte{ []byte("OFF"), []byte("ERROR"), []byte("WARN"), []byte("INFO"), []byte("DEBUG"), []byte("TRACE"), }
LevelsBytes of the logging by Level
var LevelsMap = map[string]Level{ "OFF": Off, "ERROR": Err, "WARN": Warn, "INFO": Info, "DEBUG": Debug, "TRACE": Trace, }
LevelsMap of the logging by Level string Level type
Functions ¶
Types ¶
type BaseLogger ¶
type BaseLogger struct {
// contains filtered or unexported fields
}
BaseLogger struct.
func (*BaseLogger) DebugF ¶
func (l *BaseLogger) DebugF(f string, a ...interface{})
DebugF BaseLogger
func (*BaseLogger) ErrorF ¶
func (l *BaseLogger) ErrorF(f string, a ...interface{})
ErrorF BaseLogger with formatting of the messages
func (*BaseLogger) IsEnabled ¶
func (l *BaseLogger) IsEnabled(sev Level) bool
IsEnabled function returns if the current
func (*BaseLogger) TraceF ¶
func (l *BaseLogger) TraceF(f string, a ...interface{})
TraceF BaseLogger
func (*BaseLogger) WarnF ¶
func (l *BaseLogger) WarnF(f string, a ...interface{})
WarnF BaseLogger with formatting of the messages
type ConsoleConfig ¶
type ConsoleConfig struct { //WriteErrToStdOut write error messages to os.Stdout . WriteErrToStdOut bool `json:"errToStdOut" yaml:"errToStdOut"` //WriteWarnToStdOut write warn messages to os.Stdout . WriteWarnToStdOut bool `json:"warnToStdOut" yaml:"warnToStdOut"` }
ConsoleConfig - Configuration of console based logging. All Log Levels except ERROR and WARN are written to os.Stdout The ERROR and WARN log levels can be written to os.Stdout or os.Stderr, By default they go to os.Stderr
type ConsoleWriter ¶
type ConsoleWriter struct {
// contains filtered or unexported fields
}
ConsoleWriter struct
func (*ConsoleWriter) DoLog ¶
func (cw *ConsoleWriter) DoLog(logMsg *LogMessage)
DoLog consoleWriter
func (*ConsoleWriter) InitConfig ¶
func (cw *ConsoleWriter) InitConfig(w *WriterConfig)
InitConfig ConsoleWriter
type FileConfig ¶
type FileConfig struct { //FilePath for the file based log writer DefaultPath string `json:"defaultPath" yaml:"defaultPath"` ErrorPath string `json:"errorPath" yaml:"errorPath"` WarnPath string `json:"warnPath" yaml:"warnPath"` InfoPath string `json:"infoPath" yaml:"infoPath"` DebugPath string `json:"debugPath" yaml:"debugPath"` TracePath string `json:"tracePath" yaml:"tracePath"` //RollType must indicate one for the following(case sensitive). SIZE,DAILY RollType string `json:"rollType" yaml:"rollType"` //Max Size of the of the file. Only takes into effect when the RollType="SIZE" MaxSize int64 `json:"maxSize" yaml:"maxSize"` //CompressOldFile is taken into effect if file rolling is enabled by setting a RollType. //Default implementation will just do a GZIP of the file leaving the file with <file_name>.gz CompressOldFile bool `json:"compressOldFile" yaml:"compressOldFile"` }
FileConfig - Configuration of file based logging
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
FileWriter struct
func (*FileWriter) InitConfig ¶
func (fw *FileWriter) InitConfig(w *WriterConfig)
InitConfig FileWriter
type Level ¶
type Level int
Level specifies the log level
const ( //Off - No logging Off Level = iota //Err - logging only for error level. Err //Warn - logging turned on for warning & error levels Warn //Info - logging turned on for Info, Warning and Error levels. Info //Debug - Logging turned on for Debug, Info, Warning and Error levels. Debug //Trace - Logging turned on for Trace,Info, Warning and error Levels. Trace )
type LogConfig ¶
type LogConfig struct { //Format of the log. valid values are text,json //Default is text Format string `json:"format,omitempty" yaml:"format,omitempty"` //Async Flag to indicate if the writing of the flag is asynchronous. //Default value is false Async bool `json:"async,omitempty" yaml:"async,omitempty"` //QueueSize to indicate the number log routines that can be queued to use in background //This value is used only if the async value is set to true. //Default value for the number items to be in queue 512 QueueSize int `json:"queue_size,omitempty" yaml:"queueSize,omitempty"` //Date - Defaults to time.RFC3339 pattern DatePattern string `json:"datePattern,omitempty" yaml:"datePattern,omitempty"` //IncludeFunction will include the calling function name in the log entries //Default value : false IncludeFunction bool `json:"includeFunction,omitempty" yaml:"includeFunction,omitempty"` //IncludeLineNum ,includes Line number for the log file //If IncludeFunction Line is set to false this config is ignored IncludeLineNum bool `json:"includeLineNum,omitempty" yaml:"includeLineNum,omitempty"` //DefaultLvl that will be used as default DefaultLvl string `json:"defaultLvl" yaml:"defaultLvl"` //PackageConfig that can be used to PkgConfigs []*PackageConfig `json:"pkgConfigs" yaml:"pkgConfigs"` //Writers writers for the logger. Need one for all levels //If a writer is not found for a specific level it will fallback to os.Stdout if the level is greater then Warn and os.Stderr otherwise Writers []*WriterConfig `json:"writers" yaml:"writers"` }
LogConfig - Configuration & Settings for the logger.
type LogMessage ¶
type LogMessage struct { Time time.Time `json:"timestamp"` FnName string `json:"function,omitempty"` Line int `json:"line,omitempty"` Content *bytes.Buffer `json:"msg"` Level Level `json:"level"` Buf *bytes.Buffer }
LogMessage struct.
type LogWriter ¶
type LogWriter interface { InitConfig(w *WriterConfig) DoLog(logMsg *LogMessage) io.Closer }
LogWriter interface
type Logger ¶
type Logger interface { Error(a ...interface{}) ErrorF(f string, a ...interface{}) Warn(a ...interface{}) WarnF(f string, a ...interface{}) Info(a ...interface{}) InfoF(f string, a ...interface{}) Debug(a ...interface{}) DebugF(f string, a ...interface{}) Trace(a ...interface{}) TraceF(f string, a ...interface{}) }
type PackageConfig ¶
type PackageConfig struct { //PackageName PackageName string `json:"pkgName" yaml:"pkgName"` //Level to be set valid values : OFF,ERROR,WARN,INFO,DEBUG,TRACE Level string `json:"level" yaml:"level"` }
PackageConfig configuration
type WriterConfig ¶
type WriterConfig struct { //File reference. Non mandatory but one of file or console logger is required. File *FileConfig `json:"file,omitempty" yaml:"file,omitempty"` //Console reference Console *ConsoleConfig `json:"console,omitempty" yaml:"console,omitempty"` }
WriterConfig struct