Skip to content

Support log format specifications directly from the configuration, without having to create a new formatter. #78

Open
@GarthJL1965

Description

@GarthJL1965

Currently using Log4R - which allows a Pattern Based Formatter - eg

class PatternFormatter < BasicFormatter

# Arguments to sprintf keyed to directive letters<br>
# %c - event short name<br>
# %C - event fullname<br>
# %d - date<br>
# %g - Global Diagnostic Context (GDC)<br>
# %t - trace<br>
# %m - message<br>
# %h - thread name<br>
# %p - process ID aka PID<br>
# %M - formatted message<br>
# %l - Level in string form<br>
# %x - Nested Diagnostic Context (NDC)<br>
# %X - Mapped Diagnostic Context (MDC), syntax is "%X{key}"<br>
# %% - Insert a %<br>
DirectiveTable = {
  "c" => 'event.name',
  "C" => 'event.fullname',
  "d" => 'format_date',
  "g" => 'Log4r::GDC.get()',
  "t" => '(event.tracer.nil? ? "no trace" : event.tracer[0])',
  "T" => '(event.tracer.nil? ? "no trace" : event.tracer[0].split(File::SEPARATOR)[-1])',
  "m" => 'event.data',
  "h" => '(Thread.current[:name] or Thread.current.to_s)',
  "p" => 'Process.pid.to_s',
  "M" => 'format_object(event.data)',
  "l" => 'LNAMES[event.level]',
  "x" => 'Log4r::NDC.get()',
  "X" => 'Log4r::MDC.get("DTR_REPLACE")',
  "%" => '"%"'
}

This is useful to me because I log to stdout (a simple message format for users) AND I log a timestamped message to a file as well (that may be at a different log level)

Is there a way to get this with Semantic Logger ? My first thought is to write a new Appender, but, maybe other appenders could use the 'custom formatter' as well

Cheers & Thanks

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions