Skip to content

Commit cb19b17

Browse files
authored
Merge pull request #16 from essenciary/patch-1
Example of prepending timestamp to logged messages
2 parents fe065a1 + 364b09a commit cb19b17

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,26 @@ end
318318
319319
global_logger(transformer_logger)
320320
```
321+
322+
## Add timestamp to all logging
323+
324+
```julia
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+
```
335+
336+
This will produce output similar to:
337+
```julia
338+
[ Info: 2019-09-20 17:43:54 /es/update 200
339+
┌ Debug: 2019-09-20 18:03:25 Recompiling stale cache file /.julia/compiled/v1.2/TranslationsController.ji for TranslationsController [top-level]
340+
└ @ Base loading.jl:1240
341+
┌ Error: 2019-09-20 17:43:54 ErrorException("SearchLight validation error(s) for Translations.Translation")
342+
└ @ TranslationsController ~/Dropbox/Projects/LiteCMS/app/resources/translations/TranslationsController.jl:69
343+
```

0 commit comments

Comments
 (0)