@@ -26,9 +26,7 @@ module Katip
28 -- * Framework Types
28 -- * Framework Types
31− , Namespace (..)
29+ Namespace (..)
32 , Environment (..)
30 , Environment (..)
33 , Severity (..)
31 , Severity (..)
34 , renderSeverity
32 , renderSeverity
@@ -41,9 +39,6 @@ module Katip
41 , PayloadSelection (..)
39 , PayloadSelection (..)
42 , Scribe (..)
40 , Scribe (..)
43 , LogEnv (..)
41 , LogEnv (..)
46− , LogContexts, liftPayload
47 , SimpleLogPayload, sl
42 , SimpleLogPayload, sl
49 -- ** @lens@-compatible Lenses
44 -- ** @lens@-compatible Lenses
@@ -60,7 +55,7 @@ module Katip
61 , logEnvHost
56 , logEnvHost
62 , logEnvPid
57 , logEnvPid
63− , logEnvNs
58+ , logEnvApp
64 , logEnvEnv
59 , logEnvEnv
65 , logEnvTimer
60 , logEnvTimer
66 , logEnvScribes
61 , logEnvScribes
@@ -79,15 +74,23 @@ module Katip
79 , LogStr (..)
74 , LogStr (..)
80 , logStr, ls, showLS
75 , logStr, ls, showLS
77+ -- ** 'Katip' LoggingFunctions
86 , logException
84 , logException
85+ -- ** 'KatipContext' Logging Functions
86+ -- $katipcontextlogging
89 , logItemM
90 , logItemM
90 , logExceptionM
91 , logExceptionM
93+ , LogContexts, liftPayload
92 -- * Included Scribes
95 -- * Included Scribes
93 , mkHandleScribe
96 , mkHandleScribe
@@ -101,6 +104,8 @@ module Katip
101 -- * KatipContextT - Utility transformer that provides Katip and KatipContext instances
104 -- * KatipContextT - Utility transformer that provides Katip and KatipContext instances
102 , KatipContextT
105 , KatipContextT
103 , runKatipContextT
106 , runKatipContextT
106-------------------------------------------------------------------------------
111-------------------------------------------------------------------------------
@@ -108,3 +113,91 @@ import Katip.Core
108import Katip.Monadic
113import Katip.Monadic
109import Katip.Scribes.Handle
114import Katip.Scribes.Handle
110-------------------------------------------------------------------------------
115-------------------------------------------------------------------------------
120+ These logging functions use the basic 'Katip' constraint and thus
121+will require varying degrees of explicit detail such as 'Namespace'
122+and individual log items to be passed in. These can be described as
123+the primitives of Katip logging. If you find yourself making multiple
124+log statements within a logical logging context for your app, you may
125+want to look into the 'KatipContext' family of logging functions like
126+'logFM' and 'logTM'. 'KatipContext' in most applications should be
127+considered the default. Here's an example of the pain point:
130+doDatabaseThings = do
131+ connId <- getConnectionId
132+ logF (ConnectionIDContext connId) "database" InfoS "Doing database stuff"
134+ logF (ConnectionIDContext connId) "database" InfoS "Wow, passing in the same context is getting tedious"
137+Another pain point to look out for is nesting actions that log in
138+eachother. Let's say you were writing a web app. You want to capture
139+some detail such as the user's ID in the logs, but you also want that
140+info to show up in doDatabaseThings' logs so you can associate those
141+two pieces of information:
145+webRequestHandler = do
147+ logF (UserIDContext uid) "web" InfoS "Starting web request"
151+In the above example, doDatabaseThings would overwrite that
152+UderIDContext with its own context and namespace. Sometimes this is
153+what you want and that's why 'logF' and other functions which only
154+require 'Katip' exist. If you are interested in combining log
155+contexts and namespaces, see 'KatipContext'.
159+{- $katipcontextlogging
161+ These logging functions use the 'KatipContext' constraint which is a
162+superclass of 'Katip' that also has a mechanism for keeping track of
163+the current context and namespace. This means a few things:
165+1. Functions that use 'KatipContext' like 'logFM' and 'logTM' do not
166+require you to pass in 'LogItem's or 'Namespaces', they pull them from
167+the monadic environment.
169+2. It becomes easy to add functions which add namespaces and/or
170+contexts to the current stack of them. You can (and should) make that
171+action scoped to a monadic action so that when it finishes, the
172+previous context and namespace will be automatically restored.
175+'KatipContextT' provides a simple, 'ReaderT'-based implementation of
176+the 'KatipContext' typeclass, and provides 'katipAddContext' and
177+'katipAddNamespace' functions to append to the context for the
183+ le <- initLogEnv "MyApp" "production"
184+ \-\- set up scribes here
185+ runKatipContext le () "main" $ do
186+ katipAddNamespace "nextlevel" $ do
187+ $(logTM) InfoS "Logs here will have namespace MyApp.main.nextlevel"
189+ katipAddContext TrivialContext $ do
190+ $(logTM) InfoS "Logs here will have context from TrivialContext"
192+ katipAddContext AnotherContext $ do
193+ $(logTM) InfoS "Logs here will have context from TrivialContext *merged with* context from AnotherContext!"
195+ $(logTM) InfoS "Log context restored to () and namespace to MyApp.main"
198+'katipAddNamespace' and 'katipAddContext' are one-liners, implemented
199+in terms of 'local' from 'MonadReader'. If you have a custom monad
200+transformer stack and want to add your own version of these, check out
201+<https://github.com/Soostone/katip/tree/master/katip/examples these