-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.go
67 lines (62 loc) · 1.82 KB
/
info.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
66
67
// Package golog Simple flexible go logging
// this file contains all the code for Info
package golog
import (
"fmt"
"strings"
"time"
)
// Info class, Contains all the info on what has to logged, time is the current time, Module is the specific module
// For which we are logging, level is the state, importance and type of message logged,
// Message contains the string to be logged, format is the format of string to be passed to sprintf
type Info struct {
ID uint64
Time string
Module string
Function string
Level LogLevel
Line int
Filename string
Message string
Duration time.Duration
Method string
StatusCode int
Route string
//format string
}
// Output Returns a proper string to be outputted for a particular info
func (r *Info) Output(format string) string {
msg := fmt.Sprintf(format,
r.ID, // %[1] // %{id}
r.Time, // %[2] // %{time[:fmt]}
r.Module, // %[3] // %{module}
r.Function, // %[4] // %{function}
r.Filename, // %[5] // %{filename}
r.Line, // %[6] // %{line}
r.logLevelString(), // %[7] // %{level}
r.Message, // %[8] // %{message}
r.Duration, // "%[9] // %{duration}
r.Method, // "%[10] // %{method}
r.StatusCode, // "%[11] // %{statuscode}
r.Route, // "%[12] // %{route}
)
// Ignore printf errors if len(args) > len(verbs)
if i := strings.LastIndex(msg, "%!(EXTRA"); i != -1 {
return msg[:i]
}
return msg
}
// logLevelString Returns the loglevel as string
func (r *Info) logLevelString() string {
logLevels := [...]string{
"RAW",
"ERROR",
"TRACE",
"WARNING",
"SUCCESS",
"NOTICE",
"INFO",
"DEBUG",
}
return logLevels[r.Level-1]
}