Skip to content

Using multiple loggers

cihub edited this page Dec 14, 2011 · 11 revisions

The concept

What actually a Sealog logger is? It is:

  • A set of funcs which hold the common algorithms
  • A configurations which specifies all parameters

The former is always the same, so if the loggers are 'different', it is obvious that actually the 'configurations' are different.

Therefore, this section is about logging with different configs in the same application.

Why do you need that?

Actually, you don't need it in most cases. If you need to change some parameters on the fly, read this section: Changing config on the fly. So, multiple configs should be used in case you really need different logger configurations to exist simultaneously.

Usually, the most common use-case for this functionality is logging in programs with multiple modules, e.g. you import 2-3 libraries that also use Sealog, so you want to pass them special configs. See Writing libraries with Sealog.

Another practical case is logging in extremely performance critical situations: it is sometimes not acceptable to write many exceptions case and filters in dispatching scheme for performance critical sections, because it could make things too complicated. In these cases it could be better to write a simple config, which just holds 1 constraint and 1 output and just use this config in all such critical files.

NOTE: In most situations, even in high-load apps, you don't need that, because you just should log so much. Info messages and warns for diagnostics (not frequent), errors and critical for errors (also not frequent). Debug and Trace should be disabled in production configs. So probably, this 'multi-config' feature should be used rarely in case it is absolutely needed.

How to do that

In a normal case you