blob: 7de73e728b60158a40a0a0fdbe0a005cfa2c9d10 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package main
import (
"log"
"os"
)
const (
infoLevel = 1
errLevel = 2
)
type Log struct {
level int
}
func NewLogger(logLevel string) *Log {
if logLevel == "err" {
return &Log{1}
}
if logLevel == "info" {
return &Log{2}
}
return &Log{0}
}
func (l *Log) Infof(format string, args ...interface{}) {
if l.level >= infoLevel {
log.SetPrefix("INFO: ")
log.SetOutput(os.Stdout)
log.Printf(format, args...)
}
}
func (l *Log) Errorf(format string, args ...interface{}) {
if l.level >= errLevel {
log.SetPrefix("ERROR: ")
log.SetOutput(os.Stderr)
log.Printf(format, args...)
}
}
func (l *Log) Fatalf(format string, args ...interface{}) {
log.SetPrefix("FATAL: ")
log.SetOutput(os.Stderr)
log.Fatalf(format, args...)
}
|