Skip to content

Commit b9d23eb

Browse files
author
Andrey Oskin
committed
Closes #15 Closes #16 (default format and timestamp keyword)
1 parent b77e08b commit b9d23eb

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MiniLoggers"
22
uuid = "93f3dd0f-005d-4452-894a-a31841fa4078"
33
authors = ["Andrey Oskin"]
4-
version = "0.2.6"
4+
version = "0.3.0"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/minilogger.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Supported keyword arguments include:
4444
* `flush` (default: `true`): whether to `flush` IO stream for each log message. Flush behaviour also affected by `flush_threshold` argument.
4545
* `flush_threshold::Union{Integer, TimePeriod}` (default: 0): if this argument is nonzero and `flush` is `true`, then `io` is flushed only once per `flush_threshold` milliseconds. I.e. if time between two consecutive log messages is less then `flush_threshold`, then second message is not flushed and will have to wait for the next log event.
4646
* `dtformat` (default: "yyyy-mm-dd HH:MM:SS"): if `datetime` parameter is used in `format` argument, this dateformat is applied for output timestamps.
47-
* `format` (default: "{[{datetime}]:func} {message}"): format for output log message. It accepts following keywords, which should be provided in curly brackets:
48-
* `datetime`: timestamp of the log message
47+
* `format` (default: "[{timestamp:func}] {level:func}: {message}"): format for output log message. It accepts following keywords, which should be provided in curly brackets:
48+
* `timestamp`: timestamp of the log message
4949
* `level`: name of log level (Debug, Info, etc)
5050
* `filepath`: filepath of the file, which produced log message
5151
* `basename`: basename of the filepath of the file, which produced log message
@@ -61,7 +61,7 @@ Colour information is applied recursively without override, so `{{line} {module:
6161
6262
If part of the format is not a recognised keyword, then it is just used as is, for example `{foo:red}` means that output log message contain word "foo" printed in red.
6363
"""
64-
function MiniLogger(; io = stdout, ioerr = stderr, errlevel = Error, minlevel = Info, append = false, message_limits = Dict{Any, Int}(), flush = true, format = "{[{datetime}]:func} {message}", dtformat = dateformat"yyyy-mm-dd HH:MM:SS", squash_message = true, flush_threshold = 0)
64+
function MiniLogger(; io = stdout, ioerr = stderr, errlevel = Error, minlevel = Info, append = false, message_limits = Dict{Any, Int}(), flush = true, format = "[{timestamp:func}] {level:func}: {message}", dtformat = dateformat"yyyy-mm-dd HH:MM:SS", squash_message = true, flush_threshold = 0)
6565
tio = getio(io, append)
6666
tioerr = io == ioerr ? tio : getio(ioerr, append)
6767
lastflush = Dates.value(Dates.now())
@@ -149,7 +149,7 @@ function handle_message(logger::MiniLogger, level, message, _module, group, id,
149149
for token in logger.format
150150
c = extractcolor(token, level, _module, group, id, filepath, line)
151151
val = token.val
152-
if val == "datetime"
152+
if val == "timestamp"
153153
printwcolor(iob, tsnow(logger.dtformat), c)
154154
elseif val == "message"
155155
showmessage(iob, message, logger.squash_message)

test/test02_loggerformat.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ conts(s, sub) = match(Regex(sub), s) !== nothing
88
@testset "basic format" begin
99
io = IOBuffer()
1010
logger = MiniLogger(io = io, minlevel = MiniLoggers.Debug,
11-
format = "{datetime}:{level}:{module}:{basename}:{filepath}:{line}:{group}:{module}:{id}:{message}")
11+
format = "{timestamp}:{level}:{module}:{basename}:{filepath}:{line}:{group}:{module}:{id}:{message}")
1212
with_logger(logger) do
1313
@info "foo"
1414
s = String(take!(io))
15-
@test !conts(s, "datetime")
15+
@test !conts(s, "timestamp")
1616
@test !conts(s, "level")
1717
@test !conts(s, "module")
1818
@test !conts(s, "basename")

0 commit comments

Comments
 (0)