-
Notifications
You must be signed in to change notification settings - Fork 10
/
logger.go
97 lines (78 loc) · 2.69 KB
/
logger.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
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
package coralogix
import "runtime"
// CoralogixLogger is interface for using SDK
type CoralogixLogger struct {
Category string // Current logger logs records category
LoggerManager LoggerManager // CoralogixLogger manager instance
}
// NewCoralogixLogger initialize new SDK interface instance
func NewCoralogixLogger(PrivateKey string, ApplicationName string, SubsystemName string) *CoralogixLogger {
return NewCoralogixLoggerWithCategory(
PrivateKey,
ApplicationName,
SubsystemName,
LogCategory,
)
}
// NewCoralogixLoggerWithCategory initialize new SDK interface instance with custom category
func NewCoralogixLoggerWithCategory(PrivateKey string, ApplicationName string, SubsystemName string, Category string) *CoralogixLogger {
if PrivateKey == "" {
PrivateKey = FailedPrivateKey
}
if ApplicationName == "" {
ApplicationName = NoAppName
}
if SubsystemName == "" {
SubsystemName = NoSubSystem
}
if Category == "" {
Category = LogCategory
}
NewLoggerInstance := &CoralogixLogger{
Category,
*NewLoggerManager(
PrivateKey,
ApplicationName,
SubsystemName,
true,
),
}
go NewLoggerInstance.LoggerManager.Run()
runtime.SetFinalizer(NewLoggerInstance, func(logger *CoralogixLogger) { logger.Destroy() })
return NewLoggerInstance
}
// Destroy stop logger manager and cleanup logs buffer before exit
func (logger *CoralogixLogger) Destroy() {
logger.LoggerManager.Stop()
}
// Log send record message to logger manager
func (logger *CoralogixLogger) Log(Severity uint, Text interface{}, Category string, ClassName string, MethodName string, ThreadID string) {
if Category == "" {
Category = logger.Category
}
logger.LoggerManager.AddLogLine(Severity, Text, Category, ClassName, MethodName, ThreadID)
}
// Debug send log message with DEBUG severity level
func (logger *CoralogixLogger) Debug(Text interface{}) {
logger.Log(Level.DEBUG, Text, "", "", "", "")
}
// Verbose send log message with VERBOSE severity level
func (logger *CoralogixLogger) Verbose(Text interface{}) {
logger.Log(Level.VERBOSE, Text, "", "", "", "")
}
// Info send log message with INFO severity level
func (logger *CoralogixLogger) Info(Text interface{}) {
logger.Log(Level.INFO, Text, "", "", "", "")
}
// Warning send log message with WARNING severity level
func (logger *CoralogixLogger) Warning(Text interface{}) {
logger.Log(Level.WARNING, Text, "", "", "", "")
}
// Error send log message with ERROR severity level
func (logger *CoralogixLogger) Error(Text interface{}) {
logger.Log(Level.ERROR, Text, "", "", "", "")
}
// Critical send log message with CRITICAL severity level
func (logger *CoralogixLogger) Critical(Text interface{}) {
logger.Log(Level.CRITICAL, Text, "", "", "", "")
}