@@ -6,8 +6,20 @@ import (
6
6
"strings"
7
7
)
8
8
9
- type Level int
10
- type Format int
9
+ // Constants for log level
10
+ const (
11
+ TraceLevel Level = iota
12
+ DebugLevel
13
+ InfoLevel
14
+ WarnLevel
15
+ ErrorLevel
16
+ )
17
+
18
+ // Constants for log format
19
+ const (
20
+ FormatConsole Format = iota
21
+ FormatJson
22
+ )
11
23
12
24
const (
13
25
EnvKeyLogCtx = "FLOGO_LOG_CTX"
@@ -20,17 +32,11 @@ const (
20
32
21
33
EnvKeyLogSeparator = "FLOGO_LOG_SEPARATOR"
22
34
DefaultLogSeparator = "\t "
23
-
24
- TraceLevel Level = iota
25
- DebugLevel
26
- InfoLevel
27
- WarnLevel
28
- ErrorLevel
29
-
30
- FormatConsole Format = iota
31
- FormatJson
32
35
)
33
36
37
+ type Level int
38
+ type Format int
39
+
34
40
type Logger interface {
35
41
DebugEnabled () bool
36
42
TraceEnabled () bool
@@ -121,6 +127,20 @@ func CreateLoggerFromRef(logger Logger, contributionType, ref string) Logger {
121
127
}
122
128
}
123
129
130
+ // NewLogger will create a new zap logger with same log format as engine logger
131
+ func NewLogger (name string ) Logger {
132
+ logFormat := DefaultLogFormat
133
+ envLogFormat := strings .ToUpper (os .Getenv (EnvKeyLogFormat ))
134
+ if envLogFormat == "JSON" {
135
+ logFormat = FormatJson
136
+ }
137
+ zl , lvl , _ := newZapLogger (logFormat , DefaultLogLevel )
138
+ if name == "" {
139
+ name = "flogo.custom"
140
+ }
141
+ return & zapLoggerImpl {loggerLevel : lvl , mainLogger : zl .Named (name ).Sugar ()}
142
+ }
143
+
124
144
func Sync () {
125
145
zapSync (rootLogger )
126
146
}
@@ -163,10 +183,8 @@ func configureLogging() {
163
183
}
164
184
165
185
func ToLogLevel (lvlStr string ) Level {
166
-
167
186
lvl := DefaultLogLevel
168
-
169
- switch lvlStr {
187
+ switch strings .ToUpper (lvlStr ) {
170
188
case "TRACE" :
171
189
lvl = DebugLevel
172
190
case "DEBUG" :
@@ -180,7 +198,6 @@ func ToLogLevel(lvlStr string) Level {
180
198
default :
181
199
lvl = DefaultLogLevel
182
200
}
183
-
184
201
return lvl
185
202
}
186
203
0 commit comments