JuliaLogging / LoggingExtras.jl

Composable Loggers for the Julia Logging StdLib

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filter out the source of the message in FileLogger

essenciary opened this issue · comments

I have the following setup in Genie, where logging is set up identically for file logging and console logging:

using Genie
using Logging, LoggingExtras
using Dates

const date_format = "yyyy-mm-dd HH:MM:SS"

const logger =  if Genie.config.log_to_file
                  isdir(Genie.LOG_PATH) || mkpath(Genie.LOG_PATH)
                  FileLogger(joinpath(Genie.LOG_PATH, "$(Genie.config.app_env)-$(Dates.today()).log"), always_flush = true, append = true)
                else
                  ConsoleLogger(stdout, Genie.config.log_level)
                end

timestamp_logger(logger) = TransformerLogger(logger) do log
  merge(log, (; message = "$(Dates.format(now(), date_format)) $(log.message)"))
end

DemuxLogger(MinLevelLogger(logger, Genie.config.log_level), include_current_global = true) |> timestamp_logger |> global_logger

However, the output is different. In the console I get output like:

[ Info: 2019-09-20 14:57:12 /login 200

but in the file I get the same message logged with the source:

┌ Info: 2019-09-20 14:57:12 /login 200
└ @ Genie.Router /Users/adrian/.julia/dev/Genie/src/Router.jl:144

How can I remove the source of the message in the file log, please? (aka the 2nd line starting with @ Genie.Router ... )

I think this is just something the SimpleLogger which backs the FileLogger does.
Final formattering is a property of the sink.
The Transforms and Filters only change content.

logger |> 
    x->MinLevelLogger(x, Genie.config.log_level) |> 
    x-> DemuxLogger(x, include_current_global = true) |>
    timestamp_logger |> 
    global_logger