GeezerVison is showing github.com — added SetTimestamp() · projectdiscovery/gologger@d1c3291
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: gologger.go +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
22 | 22 | } |
23 | 23 | // DefaultLogger is the default logging instance |
24 | 24 | DefaultLogger *Logger |
| 25 | + addTimestamp bool |
25 | 26 | ) |
26 | 27 |
|
27 | 28 | func init() { |
@@ -94,6 +95,12 @@ func (e *Event) TimeStamp() *Event { |
94 | 95 | return e |
95 | 96 | } |
96 | 97 |
|
| 98 | +// SetTimestamp sets a global flag indicating whether or not to add timestamps to debug logs. |
| 99 | +// If the flag is set to true, timestamps will be added to debug logs. |
| 100 | +func SetTimestamp(timestamp bool) { |
| 101 | + addTimestamp = timestamp |
| 102 | +} |
| 103 | + |
97 | 104 | // Str adds a string metadata item to the log |
98 | 105 | func (e *Event) Str(key, value string) *Event { |
99 | 106 | e.metadata[key] = value |
@@ -167,6 +174,11 @@ func Debug() *Event { |
167 | 174 | metadata: make(map[string]string), |
168 | 175 | } |
169 | 176 | event.metadata["label"] = labels[level] |
| 177 | + |
| 178 | + if addTimestamp { |
| 179 | + event.TimeStamp() |
| 180 | + } |
| 181 | + |
170 | 182 | return event |
171 | 183 | } |
172 | 184 |
|
|