Documentation
¶
Overview ¶
Package auralog is a modified Go log package with level logging and RotateWriter to automatically rotate log files. Also included a config struct to make creating a new logger cleaner, and the helper functions have been removed. The different levels are the below constants.
Index ¶
- Constants
- type Config
- type LogLevel
- type Logger
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Debugln(v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Errorln(v ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Fatalln(v ...interface{})
- func (l *Logger) Flags() int
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Infoln(v ...interface{})
- func (l *Logger) Output(level LogLevel, s string) error
- func (l *Logger) Panic(v ...interface{})
- func (l *Logger) Panicf(format string, v ...interface{})
- func (l *Logger) Panicln(v ...interface{})
- func (l *Logger) Prefix() string
- func (l *Logger) Print(v ...interface{})
- func (l *Logger) Printf(format string, v ...interface{})
- func (l *Logger) Println(v ...interface{})
- func (l *Logger) SetFlags(flag int)
- func (l *Logger) SetLevel(level LogLevel)
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) SetPrefix(prefix string)
- func (l *Logger) Trace(v ...interface{})
- func (l *Logger) Tracef(format string, v ...interface{})
- func (l *Logger) Traceln(v ...interface{})
- func (l *Logger) Warn(v ...interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
- func (l *Logger) Warnln(v ...interface{})
- func (l *Logger) Writer() io.Writer
Constants ¶
const ( Ldate = 1 << iota // the date in the local time zone: 2009/01/23 Ltime // the time in the local time zone: 01:23:23 Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime. Llongfile // full file name and line number: /a/b/c/d.go:23 Lshortfile // final file name element and line number: d.go:23. overrides Llongfile LUTC // if Ldate or Ltime is set, use UTC rather than the local time zone Lmsgprefix // move the "prefix" from the beginning of the line to before the message LstdFlags = Ldate | Ltime // initial values for the standard logger )
These flags define which text to prefix to each log entry generated by the Logger. Bits are or'ed together to control what's printed. With the exception of the Lmsgprefix flag, there is no control over the order they appear (the order listed here) or the format they present (as described in the comments). The prefix is followed by a colon only when Llongfile or Lshortfile is specified. For example, flags Ldate | Ltime (or LstdFlags) produce,
2009/01/23 01:23:23 message
while flags Ldate | Ltime | Lmicroseconds | Llongfile produce,
2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Output io.Writer // io.Writer of what to log to.
Prefix string // prefix on each line to identify the logger (but see Lmsgprefix)
Level LogLevel // What log level should be print.
Flag int
WarnFlag int // Required, flags for warn log.
ErrorFlag int // Required, flags for error, fatal, and panic logs.
DebugFlag int // Required, flags for debug logs.
TraceFlag int // Required, flags for trace logs.
}
A structure for cleaner code when initalizing Logger struct.
type LogLevel ¶
type LogLevel int
const ( LogLevelInfo LogLevel = iota LogLevelWarn LogLevelError LogLevelFatal LogLevelPanic LogLevelDebug LogLevelTrace )
Constants for log levels.
LogLevelInfo - Prints only info logs. LogLevelWarn - Prints info and warn logs. LogLevelError - Prints info, warn, and error logs. LogLevelFatal - Prints info, warn, error, fatal logs. LogLevelPanic - Prints info, warn, error, fatal, panic logs. LogLevelDebug - Prints info, warn, error, fatal, panic, debug logs. LogLevelTrace - Prints info, warn, error, fatal, panic, debug, trace logs.
func ToLogLevel ¶ added in v1.0.1
ToLogLevel(level string) return the log level constant from a string.
Example: ToLogLevel("warn") will return LogLevelWarn constant.
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. 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 ¶
New creates a new Logger. The out variable sets the destination to which log data will be written. The prefix appears at the beginning of each generated log line, or after the log header if the Lmsgprefix flag is provided. The flag argument defines the logging properties.
func (*Logger) Debug ¶
func (l *Logger) Debug(v ...interface{})
Debug level logging. Debug is equivalent to l.Print()
func (*Logger) Debugln ¶
func (l *Logger) Debugln(v ...interface{})
Debug level logging. Debugln is equivalent to l.Println()
func (*Logger) Error ¶
func (l *Logger) Error(v ...interface{})
Error level logging. Error calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.
func (*Logger) Errorf ¶
Error level logging. Errorf calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Errorln ¶
func (l *Logger) Errorln(v ...interface{})
Error level logging. Errorln calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Println.
func (*Logger) Fatal ¶
func (l *Logger) Fatal(v ...interface{})
Fatal is equivalent to l.Print() followed by a call to os.Exit(1).
func (*Logger) Fatalln ¶
func (l *Logger) Fatalln(v ...interface{})
Fatalln is equivalent to l.Println() followed by a call to os.Exit(1).
func (*Logger) Flags ¶
Flags returns the output flags for the logger. The flag bits are Ldate, Ltime, and so on.
func (*Logger) Infoln ¶ added in v1.0.4
func (l *Logger) Infoln(v ...interface{})
An alias for Print
func (*Logger) Output ¶
Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline.
func (*Logger) Panic ¶
func (l *Logger) Panic(v ...interface{})
Panic is equivalent to l.Print() followed by a call to panic().
func (*Logger) Panicln ¶
func (l *Logger) Panicln(v ...interface{})
Panicln is equivalent to l.Println() followed by a call to panic().
func (*Logger) Print ¶
func (l *Logger) Print(v ...interface{})
Print calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.
func (*Logger) Printf ¶
Printf calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Println ¶
func (l *Logger) Println(v ...interface{})
Println calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Println.
func (*Logger) SetFlags ¶
SetFlags sets the output flags for the logger. The flag bits are Ldate, Ltime, and so on.
func (*Logger) Trace ¶ added in v1.0.4
func (l *Logger) Trace(v ...interface{})
Trace level logging. Trace is equivalent to l.Print()
func (*Logger) Traceln ¶ added in v1.0.4
func (l *Logger) Traceln(v ...interface{})
Trace level logging. Traceln is equivalent to l.Println()
func (*Logger) Warn ¶
func (l *Logger) Warn(v ...interface{})
Warn level logging. Warn calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.
func (*Logger) Warnf ¶
Warn level logging. Warnf calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.