heavy-logger: Full-weight logging based on fast-logger

[ bsd3, library, system ] [ Propose Tags ] [ Report a vulnerability ]

This is Haskell logging library, which prefers functionality and extendability over light weight and simplicity. It can use fast-logger as backend, and is compatible with monad-logger interface, so it can be used in projects that already use monad-logger. heavy-logger is also integrated with text-format-heavy string formatting library.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.3.0.0, 0.3.1.0, 0.3.2.0, 0.3.2.1, 0.3.2.2
Change log ChangeLog.md
Dependencies attoparsec (>=0.13.1.0), base (>=4.8 && <5.0), bytestring (>=0.10.6), containers (>=0.5), data-default (>=0.7), fast-logger (>=2.4.10), hsyslog (>=5), lifted-base (>=0.2.3), monad-control (>=1.0.1.0), monad-logger (>=0.3.22), mtl (>=2.2.1), stm (>=2.4), template-haskell (>=2.10.0), text (>=1.2.2.1), text-format-heavy (>=0.1.5.2), th-lift (>=0.7), th-lift-instances (>=0.1), thread-local-storage (>=0.1.1), transformers-base (>=0.4.4) [details]
License BSD-3-Clause
Author Ilya Portnov
Maintainer portnov84@rambler.ru
Category System
Source repo head: git clone https://github.com/portnov/heavy-logger.git
Uploaded by IlyaPortnov at 2022-02-02T13:15:31Z
Distributions
Reverse Dependencies 6 direct, 2 indirect [details]
Downloads 3216 total (15 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-02-02 [all 1 reports]

Readme for heavy-logger-0.3.2.2

[back to package description]

heavy-logger README

This is Haskell logging library, which prefers functionality and extendability over light weight and simplicity. It can use fast-logger as backend and is compatible with monad-logger interface, so it can be used in projects that already use monad-logger. heavy-logger is integrated with text-format-heavy string formatting library.

Most notable features of heavy-logger are:

  • Several backends and possibility to write your own backends. The provided backends are:
    • Fast-logger backend. It allows to write messages to stdout, stderr or arbitrary file.
    • Syslog backend.
    • Chan backend. Writes messages to a Chan, so they can be read from the other side.
  • Possiblity to write messages to several backends in parallel.
  • Logging backend settings can be defined dynamically; it is not necessary to hardcode which backend you will use, you can load settings in runtime.
  • It is possible to change backend or it's settings in runtime (more precisely, you can change underlying backend if you use DynamicBackend as a backend, or you can change backend's filter if you use FilteringM as a backend).
  • Sane default set of logging message severity levels and possibility to define custom severity levels.
  • Logging context stacks support (aka mapped diagnostic contexts, MDC). Each logging context stack frame contains a set of named variables. These variables can be writen to the log.
  • Possibility to define log message format in the output file. For example, do you want to see event severity level first, and then time, or vice versa? It is possible to use variables from logging context stack in the formatting string.
  • Flexible events filtering mechanism. Messages are filtered based on message source and severity level. For example, you may want to write only Info messages, but also Debug messages from one module. Filtering can be performed on two stages:
    • Before event is passed to backend. This stage is context-sensitive; for example, you can enable logging only for events that happened during transaction. Context-level filters also support negation; for example, it is possible to explicitly forbid debug messages from one contexts, while debug is enabled for the whole system.
    • In the backend. For example, you can forbid to write any debug into file, but allow to write all debug into syslog.
  • Text formatting library integration. Formatting of messages by text-format-heavy is done lazily; so, you can issue a lot of debug messages, that include data that take time to present as a string; the formatting will be executed only in the case when debug output for this module is actually enabled by the filter.

This package is mostly writen with ideas of "open architecture". It exposes all internal logical pieces, so they can be combined in other order in specific applications.

All functions provided by the package work within any monad, which should be an instance of one of type classes defined by package: HasLogger, HasLogBackend, HasLogContext. Each function's signature declares only specific constraint, so if you do not need all functionality, you can implement instances only of that classes that you actually need.

There are, in general, following ways to use this package:

  • Use LoggingT monad transformer. It can be the simplest, if you already have monadic transformers stack of 1-2 transformers and you do not mind to add yet another. With LoggingT, you do not need to write any adapter instances, since LoggingT is already an instance of all required classes. This implementation automatically solves all threading-related problems, since in fact it does not have any shared state.
  • Use System.Log.Heavy.IO module. If you do not have monadic transformers at all, and your application works in pure IO, this may be the simplest way. However, this is a bit fragile, because you have to be sure that you always call logging functions only when logging state is initialized, i.e. within withLoggingIO call. This implementation stores required state in thread-local storage.
  • Implement required class instances for monadic stack that you already use in your application. For example, if you already have something like ReaderT StateT ExceptT IO, it will be probably better to add a couple of fields to StateT's state to track logging state, than change your stack to ReaderT StateT LoggingT ExceptT IO. If you wish to store logging state in some kind of shared storage (global IORef or whatever), then you should think about thread-safety by yourself.

Please refer to Haddock documentation and examples in the examples/ directory for more detailed information.