-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
114 lines (96 loc) · 2.45 KB
/
util.go
File metadata and controls
114 lines (96 loc) · 2.45 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) Jeevanandam M (https://github.com/jeevatkm)
// go-aah/log source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package log
import (
"runtime"
"strings"
"time"
"aahframework.org/essentials.v0"
)
var (
levelNameToLevel = map[string]level{
"FATAL": LevelFatal,
"PANIC": LevelPanic,
"ERROR": LevelError,
"WARN": LevelWarn,
"INFO": LevelInfo,
"DEBUG": LevelDebug,
"TRACE": LevelTrace,
}
levelToLevelName = map[level]string{
LevelFatal: "FATAL",
LevelPanic: "PANIC",
LevelError: "ERROR",
LevelWarn: "WARN",
LevelInfo: "INFO",
LevelDebug: "DEBUG",
LevelTrace: "TRACE",
}
)
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Unexported methods
//___________________________________
// String level string interface.
func (l level) String() string {
return levelToLevelName[l]
}
func levelByName(name string) level {
if level, ok := levelNameToLevel[strings.ToUpper(name)]; ok {
return level
}
return LevelUnknown
}
func isFmtFlagExists(flags []ess.FmtFlagPart, flag ess.FmtFlag) bool {
for _, f := range flags {
if f.Flag == flag {
return true
}
}
return false
}
func fetchCallerInfo() (string, int) {
// dynamic call depth calculation; skip 3 known path and get
// maximum 5 which would cover log package.
pc := make([]uintptr, 5)
n := runtime.Callers(3, pc)
if n == 0 {
// No pcs available. Stop now.
// This can happen if the first argument to runtime.Callers is large.
return "???", 0
}
pc = pc[:n] // pass only valid pcs to runtime.CallersFrames
frames := runtime.CallersFrames(pc)
// Loop to get frames.
// A fixed number of pcs can expand to an indefinite number of Frames.
for {
frame, _ := frames.Next()
// Unwinding for aah log pkg otherwise stop.
if strings.Contains(frame.File, "aahframework.org/log") {
continue
}
return frame.File, frame.Line
}
}
// isCallerInfo method to identify to fetch caller or not.
func isCallerInfo(flags []ess.FmtFlagPart) bool {
return (isFmtFlagExists(flags, FmtFlagShortfile) ||
isFmtFlagExists(flags, FmtFlagLongfile) ||
isFmtFlagExists(flags, FmtFlagLine))
}
func getReceiverByName(name string) Receiver {
switch name {
case "FILE":
return &FileReceiver{}
case "CONSOLE":
return &ConsoleReceiver{}
default:
return nil
}
}
func formatTime(t time.Time) string {
if t.IsZero() {
return ""
}
return t.Format(time.RFC3339)
}