Skip to content

Commit 9398b0e

Browse files
authored
Update Json.hs
Update haddocks
1 parent 2c947cb commit 9398b0e

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

co-log-json/src/Colog/Json.hs

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-- |
2-
-- Provide a code that allows to use structured logging. Here
3-
-- by structured logging we mean a way to add a additional structured
4-
-- data (context) to the log messages, and a tooling that allows keep
5-
-- track of the current context and attach it to all the messages.
2+
-- Top-level module for structured logging support. Structured logging provides messages in
3+
-- a machine-readable format and passing an additional user data to the messages (context)
4+
-- to the log messages, and tooling that allows keep track of the current context and attach
5+
-- it to all the messages.
66
--
77
-- Short example:
88
--
@@ -26,9 +26,9 @@
2626
-- * @(5)@ extend initial context with a new user data
2727
--
2828
-- __NOTE__ You may notice a bit of an extra boilerplate code here. It can be removed
29-
-- by using any effect handling approach, like ReaderT, mtl, various effects
29+
-- by using any effect handling approach, like ReaderT, MTL, various effects
3030
-- system or service pattern. However this library does not commit to any of
31-
-- those approaches and provide simple @IO@ interface, so there can be a light
31+
-- those approaches and provides simple @IO@ interface, so there can be a light
3232
-- wrapper with the system of your choice. E.g. The library author prefer to use
3333
-- @ImplicitParams@ extension, as you can see in cheops-logger package.
3434
--
@@ -71,28 +71,28 @@ import qualified Data.Text as T
7171

7272
-- $logger-env
7373
--
74-
-- For each message we may want to attach an additional information
74+
-- For each message we attach additional information
7575
--
7676
-- * @thread id@ — it can be useful to group messages by the
77-
-- thread when debugging, espeacially in a case if thread
78-
-- can be associated with the request processing.
77+
-- thread when debugging, especially in a case if a thread
78+
-- can be associated with the request processing.
7979
--
80-
-- * @namespace@ — '.' delimited text that describes the componet
81-
-- that the log was emited from. It allows simple logs
82-
-- filtering in external system, or in the logger action.
80+
-- * @namespace@ — '.' delimited text that describes the component
81+
-- that the log was emitted from. It allows simple logs
82+
-- filtering in an external system, or in the logger action.
8383
--
8484
-- * @severity@ — information how urgent the message is.
8585
--
86-
-- * @user_data@ - any user data in a key-value form, key is a
87-
-- text value, and value is an json-encoded value.
86+
-- * @user_data@ - any user data in a key-value form, the key is a
87+
-- text value, and the value is a JSON-encoded value.
8888
--
89-
-- In order to keep track of that information we introduce 'LoggerEnv' handle,
90-
-- we can emit messages using that hadle, see writing logs section,
91-
-- and modify current context, see adding context section.
89+
-- In order to keep track of that information we introduce 'LoggerEnv' handle.
90+
-- It can be used to emit messages with additional information,
91+
-- see writing logs section, and modify current context, see adding context section.
9292

93-
-- | Logger environment, is used to keep information about
93+
-- | Logger environment is used to keep information about
9494
-- the current context and modify it. When any log message
95-
-- is emitted the current cotext is added to the message.
95+
-- is emitted the current context is added to the message.
9696
data LoggerEnv = LoggerEnv
9797
{ action :: LogAction IO Message -- ^ Internal log action.
9898
, context :: Seq.Seq Structured -- ^ Current context.
@@ -102,13 +102,23 @@ data LoggerEnv = LoggerEnv
102102
emptyLogger :: LoggerEnv
103103
emptyLogger = LoggerEnv (LogAction $ \_ -> pure ()) Seq.empty
104104

105-
-- | Covert ordinary co-log action into 'LoggerEnv' this way
105+
-- | Covert ordinary colog action into 'LoggerEnv' this way
106106
-- we can keep track of the current context and modify it.
107+
--
108+
-- @
109+
-- let ctx = 'mkLogger' ('Colog.Json.Action.logToHandle' 'System.IO.stderr')
110+
-- in 'logDebug' ctx "message"
111+
-- @
112+
--
107113
mkLogger :: LogAction IO Message -> LoggerEnv
108114
mkLogger action = LoggerEnv action Seq.empty
109115

110116
-- | Covert 'LoggerEnv' back into colog 'LogAction', so we can
111117
-- combie it with the rest of the colog ecosystem.
118+
--
119+
-- @
120+
-- 'Colog.Core.Action.cfilter' (\(sev, _) -> sev > 'Colog.Json.DebugS') 'unLogger' ctx
121+
-- @
112122
unLogger :: LoggerEnv -> LogAction IO (Severity, LogStr)
113123
unLogger (LoggerEnv action st) = LogAction $ \(lvl, msg) -> do
114124
tid <- myThreadId
@@ -161,10 +171,11 @@ addNamespace ns LoggerEnv{..} = LoggerEnv{context=context Seq.|> Segment ns, ..}
161171
-- log concatenation. Currently it uses 'Data.Text.Lazy.Builder' but it's an implementation
162172
-- detail and may change in the future.
163173
--
164-
-- 'LogStr' implements 'Data.String.IsString' class, so you can write constant strings
165-
-- without any boilerplate. For other types you should use 'ls' or 'showLS' names are
166-
-- taken from 'Katip' interface.
167-
174+
-- 'LogStr' can be created is several ways:
175+
-- * From the string literal using 'Data.String.IsString' interface
176+
-- * From the string like data that can be converted to text, using 'ls' function
177+
-- * From the type that has a 'Show' instance using 'showLS'
178+
--
168179

169180
-- $writing-helpers
170181
-- Library provides helper for each 'Severity' level.

0 commit comments

Comments
 (0)