contra-tracers: A logging library built on top of contra-tracer to make configuring and declaring multiple tracers easy (via generics).

[ contravariant, generics, library, logging, mpl ] [ Propose Tags ]

Modules

  • Data
    • Generics
      • Data.Generics.Tracers
    • Data.Severity

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 1.0.0
Change log CHANGELOG.md
Dependencies aeson, base (>=4.7 && <5), contra-tracer [details]
License MPL-2.0
Copyright 2021 KtorZ
Author KtorZ <matthias.benkort@gmail.com>
Maintainer matthias.benkort@gmail.com
Category Logging, Contravariant, Generics
Home page https://github.com/cardanosolutions/ogmios#readme
Bug tracker https://github.com/cardanosolutions/ogmios/issues
Source repo head: git clone https://github.com/cardanosolutions/ogmios
Uploaded by KtorZ at 2022-02-24T20:26:23Z
Distributions
Downloads 142 total (18 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2022-02-25 [all 2 reports]

Readme for contra-tracers-1.0.0

[back to package description]

contra-tracers

Overview

An opinionated, simple and easy-to-use logging library leveraging contravariant functors to provide structured multi-component logger capability to real application.

Usage

-- Some HTTP log message represented as Haskell values.

data HttpLog
    = SomeHttpLog
    | SomeHttpWarning
    deriving stock (Generic)
    deriving anyclass (ToJSON)

nstance HasSeverityAnnotation HttpLog
   getSeverityAnnotation = \case
       SomeHttpLog -> Info
       SomeHttpWarning -> Warning

-- Some DB log message represented as Haskell values.

data DbLog = SomeDbLog
    deriving stock (Generic)
    deriving anyclass (ToJSON)

nstance HasSeverityAnnotation HttpLog
   getSeverityAnnotation = \case
       SomeHttpLog -> Info
       SomeHttpWarning -> Warning

-- Applications tracers, defined as a record of higher-kinded types. We
-- have in particular 'TracerHKD Concrete a ~ a', which effectively makes
-- the 'Tracers' record a plain record of tracers once instantiated.

data Tracers m (kind :: TracerDefinition) = Tracers
    { tracerHttp :: TracerHKD kind (Tracer m HttpLog)
    , tracerDb   :: TracerHKD kind (Tracer m DbLog)
    } deriving stock (Generic)

-- The default configuration, setting all tracers to 'Info' min severity.
-- In practice, you may want to obtain the configuration from a config
-- file or from command-line options.
emptyConfiguration :: Tracers m MinSeverities
emptyConfiguration = defaultTracers Info

main :: IO ()
main = do
    withStdoutTracer mempty emptyConfiguration $ \tracers -> do
        concurrently_
            (myHttpApplication (tracerHttp tracers))
            (myDbApplication (tracerDb  tracers))

:gift: Contributing | :floppy_disk: Changelog