forked from ejoy/goscon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
65 lines (53 loc) · 1.08 KB
/
log.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// date : 2014-06-07
// author: xjdrew
//
package main
import (
"io"
"log"
"os"
"runtime"
)
var logger *log.Logger
var logLevel int
func init() {
//logger = log.New(io.Writer(os.Stderr), "", log.Ldate | log.Lmicroseconds | log.Lshortfile)
logger = log.New(io.Writer(os.Stderr), "", log.Ldate|log.Lmicroseconds)
}
func _print(format string, a ...interface{}) {
logger.Printf(format, a...)
}
func Debug(format string, a ...interface{}) {
if logLevel > 2 {
_print(format, a...)
}
}
func Info(format string, a ...interface{}) {
if logLevel > 1 {
_print(format, a...)
}
}
func Error(format string, a ...interface{}) {
if logLevel > 0 {
_print(format, a...)
}
}
func Panic(format string, a ...interface{}) {
_print(format, a...)
panic("!!")
}
func Log(format string, a ...interface{}) {
_print(format, a...)
}
func LogCurStack(format string, a ...interface{}) {
_print(format, a...)
buf := make([]byte, 8192)
runtime.Stack(buf, false)
_print("!!!!!stack!!!!!: %s", buf)
}
func Recover() {
if err := recover(); err != nil {
LogCurStack("goroutine failed:%v", err)
}
}