Documentation
¶
Overview ¶
Package logo contains an extension of the log package from the standard library. Its main features are: - Logging filename, function and line number where the logger was called. - Multiple log Level's - Easy start (You don't need to create a logger instance) - Colored output of log Level's via ANSI-Code - String and JSON output - Can write to any io.Writer
Example:
logo.Print("Hallo")
Index ¶
- Constants
- Variables
- func Config(flag Flag)
- func Debug(v ...interface{})
- func Error(v ...interface{})
- func Fatal(v ...interface{})
- func Info(v ...interface{})
- func Log(level Level, v ...interface{})
- func Print(v ...interface{})
- func Warn(v ...interface{})
- type Flag
- type Level
- type Logger
- func (l *Logger) Config(flags Flag)
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Log(level Level, v ...interface{})
- func (l *Logger) Print(v ...interface{})
- func (l *Logger) Warn(v ...interface{})
Constants ¶
const ( DateFlag = 1 << Flag(iota) TimeFlag MillisFlag FilenameFlag FuncnameFlag JsonFlag )
Different Flag's to configure the equivalent property in the logger.
const ( DebugLevel = Level(iota) InfoLevel WarnLevel ErrorLevel PrintLevel FatalLevel AllLevels = DebugLevel )
The log Level's following are sorted in ascending order of priority. DebugLevel(AllLevels), InfoLevel, WarnLevel, ErrorLevel, FatalLevel and PrintLevel. So the highest Level is PrintLevel, the lowest is DebugLevel(PrintLevel). A log message is only logged if its Level is greater or equal to the Level of the Logger.
Variables ¶
var ( // Default is the Logger used by all functions that don't get called on a concrete logger instance. // For example, if you write logo.Info("Logo"), that uses this Default Logger. Default = New(DateFlag | TimeFlag | MillisFlag | FilenameFlag | FuncnameFlag) )
Functions ¶
func Config ¶
func Config(flag Flag)
Config configures the Default Logger according to the given flags.
Types ¶
type Level ¶
type Level uint8
Level decides which messages get logged in a Logger.
func (Level) ColorizedString ¶
ColorizedString returns the colorized name of the log Level.
type Logger ¶
type Logger struct {
// Date specifies whether the date should be displayed.
Date bool
// Time specifies whether the time should be displayed.
Time bool
// Millis specifies whether the milliseconds should be displayed.
Millis bool
// Filename specifies whether the filename and line should be displayed where the
// Logger was called.
Filename bool
// Funcname specifies whether the struct and function should be displayed where
// the Logger was called.
Funcname bool
// Json specifies whether the output should be in Json format.
Json bool
// Output is the writer to which the log should be written.
Output io.Writer
// DateFormat is the date format of the output.
DateFormat string
// TimeFormat is the time format of the output.
TimeFormat string
// Level is the log level of this logger. The logger only logs messages with a
// level greater or equal to the log level. By default, AllLevels is selected,
// which logs everything.
Level Level
}
Logger logs messages with various configuration options.
func NewDefault ¶
func NewDefault() *Logger
NewDefault creates a new Logger with default flags. If you want to create a custom Logger, use New() instead or change the configuration options on the returned Logger.
func (*Logger) Debug ¶
func (l *Logger) Debug(v ...interface{})
Debug logs a message with DebugLevel.
func (*Logger) Error ¶
func (l *Logger) Error(v ...interface{})
Error logs a message with ErrorLevel.
func (*Logger) Fatal ¶
func (l *Logger) Fatal(v ...interface{})
Fatal logs a message with FatalLevel and panics with the message in v.