-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.go
50 lines (40 loc) · 957 Bytes
/
default.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
package costtime
import (
"log"
"os"
)
var logDirectory = "costtimelog"
var logDefaultName = "default"
func init() {
info, err := os.Stat(logDirectory)
if err != nil {
log.Println(err)
}
if info == nil {
err = os.Mkdir(logDirectory, os.ModeDir|os.ModeTemporary|os.ModePerm)
if err != nil {
log.Println(err)
}
} else {
if !info.IsDir() {
log.Panicf("%s is exists. and not directory.", logDirectory)
}
}
}
var defaultCost *CostTime = New(logDefaultName)
// CostLog 计算消耗的时间
func CostLog(name string, run func()) {
defaultCost.CostLog(name, run)
}
// Cost 里面计算消耗时间
func Cost(run func()) {
defaultCost.Cost(run)
}
// SetLogCondition 设置输出cost条件
func SetLogCondition(cond ConditionFunc) {
defaultCost.SetLogCondition(cond)
}
// SetEventCost 设置输出cost事件. 可以做邮件通知. 钉釘等办公通知
func SetEventCost(event EventFunc) {
defaultCost.SetEeventCost(event)
}