Skip to content

Commit 07fcbd3

Browse files
authored
Example of prepending timestamp to logged messages
Added an example of automatically prepending the timestamp to all logged messages.
1 parent fe065a1 commit 07fcbd3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,17 @@ end
318318
319319
global_logger(transformer_logger)
320320
```
321+
322+
## Add timestamp to all logging
323+
324+
```
325+
using Logging, LoggingExtras, Dates
326+
327+
const date_format = "yyyy-mm-dd HH:MM:SS"
328+
329+
timestamp_logger(logger) = TransformerLogger(logger) do log
330+
merge(log, (; message = "$(Dates.format(now(), date_format)) $(log.message)"))
331+
end
332+
333+
ConsoleLogger(stdout, Logging.Debug) |> timestamp_logger |> global_logger
334+
```

0 commit comments

Comments
 (0)