Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(message ...interface{})
- func Debugf(message ...interface{})
- func Error(message ...interface{})
- func Errorf(message ...interface{})
- func Flush()
- func GetLogWriter() (io.Writer, error)
- func Info(message ...interface{})
- func Infof(message ...interface{})
- func InitLogger(level, directory, process string, humanRedable bool) error
- func IsTerminal() bool
- func Monitor(m *Metric)
- func SetBufferSize(bufferSize int) error
- func SetLogType(logType string)
- func SetLogWriter(writer io.Writer) error
- func Warning(message ...interface{})
- func Warningf(message ...interface{})
- type Log
- type Logger
- type Metric
Constants ¶
const ( // MONITOR monitoring logs flag MONITOR string = "MON" // ERROR error logs flag ERROR string = "ERR" // WARNING Warning logs flag string WARNING string = "WAR" // INFO informative log message flag string INFO string = "INF" // DEBUG debug logs flag string DEBUG string = "DEB" )
const ( WHITE = 0 RED int = iota + 31 GREEN YELLOW BLUE MAGENTA )
Constants representing colors to tty color constants to be used as "\033[COLORm" Eg: \033[31m for RED
Variables ¶
var LogColors = map[string]int{ MONITOR: MAGENTA, ERROR: RED, WARNING: GREEN, INFO: BLUE, DEBUG: YELLOW, }
LogColors is map of log level to color
LogLevels defines loglevel priorities 0 highest and 3 lowest
Functions ¶
func GetLogWriter ¶
GetLogWriter returns an io.Writer for log if already created returns the same otherwise creates a new buffered Writer and returns
func InitLogger ¶
InitLogger initialise logger object with logWriter and log level
func SetBufferSize ¶
SetBufferSize sets the buffer size for buffering logs the logs will be flushed anyways upon stop of the service
func SetLogType ¶
func SetLogType(logType string)
SetLogType sets the log type This is more like a lable saying the type of log some possible log types would be application,error,
Types ¶
type Log ¶
type Log struct { ProcessName string `json:"service"` LogType string `json:"logtype"` LogTime string `json:"timestamp"` HostName string `json:"host"` Msg string `json:"message"` Level string `json:"loglevel"` ProcessID int `json:"processid"` FileName string `json:"filename"` LineNum int `json:"linenum"` }
Log defines the structure of the log message or the log format
func GetLog ¶
func GetLog() Log
GetLog returns log struct GetLog returns the log struct with essential common data filled in
type Logger ¶
type Logger struct { LogLevel int BufferSizeBytes int LogType string // contains filtered or unexported fields }
Logger struct to hold the log level and the Writer
func (Logger) Log ¶
Log given the stack depth and level with an array of messages decides if to be Written to logs ans writes to log with FileName and LineNum taken from runtime Info
func (*Logger) SetBufferSize ¶
SetBufferSize sets buffer size as bytes
func (*Logger) SetLogType ¶
SetLogType sets the log type This is more like a lable saying the type of log some possible log types would be application,error,
func (*Logger) SetLogWriter ¶
SetLogWriter sets default writer
type Metric ¶
type Metric struct { Name string `json:"name"` Tags map[string]string `json:"tags"` Fields map[string]interface{} `json:"fields"` }
Metric format for metrics