diff --git a/src/System/Logger.hs b/src/System/Logger.hs index 01ef70b5ce46d9d524eac10eab7d6edc19c4d9bc..6b33989e33c3a6fe05dc092af6cb4994f8628345 100644 --- a/src/System/Logger.hs +++ b/src/System/Logger.hs @@ -5,7 +5,7 @@ {-# LANGUAGE OverloadedStrings #-} -- | Small layer on top of @fast-logger@ which adds log-levels and --- timestamp support and not much more. +-- timestamp support (using @date-cache@) and not much more. module System.Logger ( Level (..) , Output (..) @@ -86,6 +86,7 @@ newtype DateFormat = DateFormat instance IsString DateFormat where fromString = DateFormat . pack +-- | ISO 8601 date-time format. iso8601UTC :: DateFormat iso8601UTC = "%Y-%0m-%0dT%0H:%0M:%0SZ" diff --git a/src/System/Logger/Message.hs b/src/System/Logger/Message.hs index 72c0e3fe972058e1f6b223be42e29002a1807c4d..f3f80770bb927cfbc8c3f9db90c0abe11c534c48 100644 --- a/src/System/Logger/Message.hs +++ b/src/System/Logger/Message.hs @@ -5,13 +5,23 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} +-- | 'Msg' and 'ToBytes' assist in constructing log messages. +-- For example: +-- +-- @ +-- > g <- new defSettings { bufSize = 1, output = StdOut } +-- > info g $ msg "some text" ~~ "key" .= "value" ~~ "okay" .= True +-- 2014-04-28T21:18:20Z, I, some text, key=value, okay=True +-- > +-- @ module System.Logger.Message ( ToBytes (..) , Msg , msg , field - , (=:) + , (.=) , (+++) + , (~~) , val , render ) where @@ -62,22 +72,29 @@ instance ToBytes Bool where -- | Type representing log messages. newtype Msg = Msg { builders :: [Builder] } --- | Log some value. +-- | Turn some value into a 'Msg'. msg :: ToBytes a => a -> Msg -> Msg msg p (Msg m) = Msg (bytes p : m) --- | Log some field, i.e. a key-value pair delimited by \"=\". -field, (=:) :: ToBytes a => ByteString -> a -> Msg -> Msg +-- | Render some field, i.e. a key-value pair delimited by \"=\". +field :: ToBytes a => ByteString -> a -> Msg -> Msg field k v (Msg m) = Msg $ bytes k <> B.byteString "=" <> bytes v : m -infixr 5 =: -(=:) = field +-- | Alias of 'field'. +(.=) :: ToBytes a => ByteString -> a -> Msg -> Msg +(.=) = field +infixr 5 .= -infixr 5 +++ +-- | Alias of '.' with lowered precedence to allow combination with '.=' +-- without requiring parentheses. +(~~) :: (b -> c) -> (a -> b) -> a -> c +(~~) = (.) +infixr 4 ~~ -- | Concatenate two 'ToBytes' values. (+++) :: (ToBytes a, ToBytes b) => a -> b -> Builder a +++ b = bytes a <> bytes b +infixr 5 +++ -- | Type restriction. Useful to disambiguate string literals when -- using @OverloadedStrings@ pragma.