Skip to content
Snippets Groups Projects
Commit 1b94f63b authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

added *f logging functions and some comment formatting

parent 21eddd61
Branches
No related tags found
3 merge requests!90Develop,!61Resolve "Logger with formatting directives",!53V.0.1.0 Codename Threadbare
...@@ -58,8 +58,8 @@ func get() *Logger { ...@@ -58,8 +58,8 @@ func get() *Logger {
return logger return logger
} }
//Loglevel sets the verbosity of the logger // Loglevel sets the verbosity of the logger
//Defaults to INFO // Defaults to INFO
func Loglevel(level Level) { func Loglevel(level Level) {
l := get() l := get()
l.lock.Lock() l.lock.Lock()
...@@ -67,8 +67,8 @@ func Loglevel(level Level) { ...@@ -67,8 +67,8 @@ func Loglevel(level Level) {
l.Loglevel = level l.Loglevel = level
} }
//Output defines the output of the logger // Output defines the output of the logger
//Defaults to os.Stderr // Defaults to os.Stderr
func Output(out io.Writer) { func Output(out io.Writer) {
l := get() l := get()
l.lock.Lock() l.lock.Lock()
...@@ -76,8 +76,8 @@ func Output(out io.Writer) { ...@@ -76,8 +76,8 @@ func Output(out io.Writer) {
l.DefaultWriter = out l.DefaultWriter = out
} }
//LoglevelOutput defines a special output // LoglevelOutput defines a special output
//for a certain log level // for a certain log level
func LoglevelOutput(level Level, out io.Writer) { func LoglevelOutput(level Level, out io.Writer) {
l := get() l := get()
l.lock.Lock() l.lock.Lock()
...@@ -88,44 +88,77 @@ func LoglevelOutput(level Level, out io.Writer) { ...@@ -88,44 +88,77 @@ func LoglevelOutput(level Level, out io.Writer) {
} }
} }
//Debug passes the DEBUG flag and a // Debug passes the DEBUG flag and a
//message to the logger // message to the logger
func Debug(args ...interface{}) { func Debug(args ...interface{}) {
log(DEBUG, args...) log(DEBUG, args...)
} }
//Info passes the INFO flag and a // Info passes the INFO flag and a
//message to the logger // message to the logger
func Info(args ...interface{}) { func Info(args ...interface{}) {
log(INFO, args...) log(INFO, args...)
} }
//Warn passes the WARNING flag and a // Warn passes the WARNING flag and a
//message to the logger // message to the logger
func Warn(args ...interface{}) { func Warn(args ...interface{}) {
log(WARNING, args...) log(WARNING, args...)
} }
//Error passes the ERROR flag and a // Error passes the ERROR flag and a
//message to the logger // message to the logger
func Error(args ...interface{}) { func Error(args ...interface{}) {
log(ERROR, args...) log(ERROR, args...)
} }
//Fatal passes the FATAL flag and a // Fatal passes the FATAL flag and a
//message to the logger and calls // message to the logger and calls
//os.Exit(1) // os.Exit(1)
func Fatal(args ...interface{}) { func Fatal(args ...interface{}) {
log(FATAL, args...) log(FATAL, args...)
os.Exit(1) os.Exit(1)
} }
//Panic passes the PANIC flag and a // Debugf passes the DEBUG flag,
//message to the logger // a formatted string and a
//Also calls builtin.panic() // message to the logger
func Panic(args ...interface{}) { func Debugf(format string, args ...interface{}) {
log(PANIC, args...) logf(DEBUG, format, args...)
panic(args) }
// Infof passes the INFO flag,
// a formatted string and and a
// message to the logger
func Infof(format string, args ...interface{}) {
logf(INFO, format, args...)
}
// Warnf passes the WARNING flag,
// a formatted string and and a
// message to the logger
func Warnf(format string, args ...interface{}) {
logf(WARNING, format, args...)
}
// Errorf passes the ERROR flag,
// a formatted string and and a
// message to the logger
func Errorf(format string, args ...interface{}) {
logf(ERROR, format, args...)
}
// Fatalf passes the FATAL flag,
// a formatted string and and a
// message to the logger and calls
// os.Exit(1)
func Fatalf(format string, args ...interface{}) {
logf(FATAL, format, args...)
os.Exit(1)
}
func logf(level Level, format string, args ...interface{}) {
log(level, fmt.Sprintf(format, args...))
} }
func log(level Level, args ...interface{}) { func log(level Level, args ...interface{}) {
...@@ -164,8 +197,6 @@ func callers() (string, int) { ...@@ -164,8 +197,6 @@ func callers() (string, int) {
func prefix(level Level) string { func prefix(level Level) string {
switch level { switch level {
case PANIC:
return "PANIC"
case FATAL: case FATAL:
return "FATAL" return "FATAL"
case ERROR: case ERROR:
......
...@@ -7,8 +7,7 @@ type Level uint8 ...@@ -7,8 +7,7 @@ type Level uint8
// Constants for more verbose integer // Constants for more verbose integer
// values // values
const ( const (
PANIC Level = iota FATAL Level = iota
FATAL
ERROR ERROR
WARNING WARNING
INFO INFO
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment