diff --git a/Project.toml b/Project.toml index b380089..2adf7e0 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "Memento" uuid = "f28f55f0-a522-5efc-85c2-fe41dfb9b2d9" license = "MIT" authors = ["Invenia Technical Computing"] -version = "1.1.0" +version = "1.1.1" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/Memento.jl b/src/Memento.jl index 826c90f..594a967 100644 --- a/src/Memento.jl +++ b/src/Memento.jl @@ -51,6 +51,7 @@ include("config.jl") include("exceptions.jl") include("memento_test.jl") include("deprecated.jl") +include("precompile.jl") # Initializing at compile-time will work as long as the loggers which are added do not # contain references to stdout. @@ -65,4 +66,5 @@ function __init__() Memento.register(LOGGER) end +_precompile_() end diff --git a/src/config.jl b/src/config.jl index 3ecc668..c3a9f56 100644 --- a/src/config.jl +++ b/src/config.jl @@ -39,7 +39,8 @@ function config!( setpropagating!(logger, propagate) handler = DefaultHandler( stdout, - DefaultFormatter(fmt), Dict{Symbol, Any}(:is_colorized => colorized) + DefaultFormatter(fmt), + Dict{Symbol, Any}(:is_colorized => colorized), ) logger.handlers["console"] = handler register(logger) diff --git a/src/formatters.jl b/src/formatters.jl index c23060b..43e04d9 100644 --- a/src/formatters.jl +++ b/src/formatters.jl @@ -25,11 +25,11 @@ Ex) "[{level} | {name}]: {msg}" will print message of the form struct DefaultFormatter <: Formatter fmt_str::AbstractString tokens::Vector{Pair{Symbol, Bool}} - output_tz::Dates.TimeZone + output_tz::Union{Dates.TimeZone, Nothing} function DefaultFormatter( fmt_str::AbstractString=DEFAULT_FMT_STRING, - output_tz=localzone(), + output_tz=nothing, ) #r"(?<={).+?(?=}) tokens = map(eachmatch(r"({.+?})|(.+?)", fmt_str)) do m @@ -45,6 +45,7 @@ struct DefaultFormatter <: Formatter end end + """ format(::DefaultFormatter, ::Record) -> String @@ -77,7 +78,9 @@ function format(fmt::DefaultFormatter, rec::Record) value = string(" stack:[", join(str_frames, ", "), "]") elseif content === :date value = if tmp_val isa ZonedDateTime - Dates.format(astimezone(tmp_val, fmt.output_tz), DATE_FMT_STRING) + # `localzone` is expensive, so we don't call it until it is required. + tzout = fmt.output_tz === nothing ? localzone() : fmt.output_tz + Dates.format(astimezone(tmp_val, tzout), DATE_FMT_STRING) elseif tmp_val isa DateTime Dates.format(tmp_val, DATE_FMT_STRING) else diff --git a/src/precompile.jl b/src/precompile.jl new file mode 100644 index 0000000..559e008 --- /dev/null +++ b/src/precompile.jl @@ -0,0 +1,4 @@ +function _precompile_() + # Precompiling this one methods seems to cut our allocations during package loading in half. + @assert precompile(Tuple{typeof(Base.log), Memento.Logger, Memento.DefaultRecord}) +end