Modulekatip-0.8.8.0Haskell2010
Katip.Core
This module is not meant to be imported directly and may contain internal mechanisms that will change without notice.
- 20 types
- 3 classes
- 60 values
- Packagekatip-0.8.8.0
- Exports83
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceCore.hs
Represents a heirarchy of namespaces going from general to specific. For instance: ["processname", "subsystem"]. Note that single-segment namespaces can be created using IsString/OverloadedStrings, so "foo" will result in Namespace ["foo"].
Constructors
NamespaceunNamespace :: [Text]
Instances12Eq, Ord, Read, Show, IsString, Generic, …
Eq NamespaceDefined in katip-0.8.8.0 · Katip.CoreOrd NamespaceDefined in katip-0.8.8.0 · Katip.CoreRead NamespaceDefined in katip-0.8.8.0 · Katip.CoreShow NamespaceDefined in katip-0.8.8.0 · Katip.CoreIsString NamespaceDefined in katip-0.8.8.0 · Katip.CoreGeneric NamespaceDefined in katip-0.8.8.0 · Katip.CoreSemigroup NamespaceDefined in katip-0.8.8.0 · Katip.CoreMonoid NamespaceDefined in katip-0.8.8.0 · Katip.CoreFromJSON NamespaceDefined in katip-0.8.8.0 · Katip.CoreToJSON NamespaceDefined in katip-0.8.8.0 · Katip.CoreLift NamespaceDefined in katip-0.8.8.0 · Katip.Coretype Rep Namespace = D1 ('MetaDataDefined in katip-0.8.8.0 · Katip.Core"Namespace"
"Katip.Core"
"katip-0.8.8.0-Z7JfszSB51D3etmAJRu1J"
'True) (C1 ('MetaCons"Namespace"
'PrefixI 'True) (S1 ('MetaSel ('Just"unNamespace"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Text])))
Ready namespace for emission with dots to join the segments.
Application environment, like prod, devel, testing.
Constructors
Instances9Eq, Ord, Read, Show, IsString, Generic, …
Eq EnvironmentDefined in katip-0.8.8.0 · Katip.CoreOrd EnvironmentDefined in katip-0.8.8.0 · Katip.CoreRead EnvironmentDefined in katip-0.8.8.0 · Katip.CoreShow EnvironmentDefined in katip-0.8.8.0 · Katip.CoreIsString EnvironmentDefined in katip-0.8.8.0 · Katip.CoreGeneric EnvironmentDefined in katip-0.8.8.0 · Katip.CoreFromJSON EnvironmentDefined in katip-0.8.8.0 · Katip.CoreToJSON EnvironmentDefined in katip-0.8.8.0 · Katip.Coretype Rep Environment = D1 ('MetaDataDefined in katip-0.8.8.0 · Katip.Core"Environment"
"Katip.Core"
"katip-0.8.8.0-Z7JfszSB51D3etmAJRu1J"
'True) (C1 ('MetaCons"Environment"
'PrefixI 'True) (S1 ('MetaSel ('Just"getEnvironment"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))
Instances11Bounded, Enum, Eq, Ord, Read, Show, …
Bounded SeverityDefined in katip-0.8.8.0 · Katip.CoreEnum SeverityDefined in katip-0.8.8.0 · Katip.CoreEq SeverityDefined in katip-0.8.8.0 · Katip.CoreOrd SeverityDefined in katip-0.8.8.0 · Katip.CoreRead SeverityDefined in katip-0.8.8.0 · Katip.CoreShow SeverityDefined in katip-0.8.8.0 · Katip.CoreGeneric SeverityDefined in katip-0.8.8.0 · Katip.CoreFromJSON SeverityDefined in katip-0.8.8.0 · Katip.CoreToJSON SeverityDefined in katip-0.8.8.0 · Katip.CoreLift SeverityDefined in katip-0.8.8.0 · Katip.Coretype Rep Severity = D1 ('MetaDataDefined in katip-0.8.8.0 · Katip.Core"Severity"
"Katip.Core"
"katip-0.8.8.0-Z7JfszSB51D3etmAJRu1J"
'False) (((C1 ('MetaCons"DebugS"
'PrefixI 'False) U1 :+: C1 ('MetaCons"InfoS"
'PrefixI 'False) U1) :+: (C1 ('MetaCons"NoticeS"
'PrefixI 'False) U1 :+: C1 ('MetaCons"WarningS"
'PrefixI 'False) U1)) :+: ((C1 ('MetaCons"ErrorS"
'PrefixI 'False) U1 :+: C1 ('MetaCons"CriticalS"
'PrefixI 'False) U1) :+: (C1 ('MetaCons"AlertS"
'PrefixI 'False) U1 :+: C1 ('MetaCons"EmergencyS"
'PrefixI 'False) U1)))
Instances11Bounded, Enum, Eq, Ord, Read, Show, …
Bounded VerbosityDefined in katip-0.8.8.0 · Katip.CoreEnum VerbosityDefined in katip-0.8.8.0 · Katip.CoreEq VerbosityDefined in katip-0.8.8.0 · Katip.CoreOrd VerbosityDefined in katip-0.8.8.0 · Katip.CoreRead VerbosityDefined in katip-0.8.8.0 · Katip.CoreShow VerbosityDefined in katip-0.8.8.0 · Katip.CoreGeneric VerbosityDefined in katip-0.8.8.0 · Katip.CoreFromJSON VerbosityDefined in katip-0.8.8.0 · Katip.CoreToJSON VerbosityDefined in katip-0.8.8.0 · Katip.CoreLift VerbosityDefined in katip-0.8.8.0 · Katip.Coretype Rep Verbosity = D1 ('MetaDataDefined in katip-0.8.8.0 · Katip.Core"Verbosity"
"Katip.Core"
"katip-0.8.8.0-Z7JfszSB51D3etmAJRu1J"
'False) ((C1 ('MetaCons"V0"
'PrefixI 'False) U1 :+: C1 ('MetaCons"V1"
'PrefixI 'False) U1) :+: (C1 ('MetaCons"V2"
'PrefixI 'False) U1 :+: C1 ('MetaCons"V3"
'PrefixI 'False) U1))
Instances8Eq, Show, IsString, Generic, Semigroup, Monoid, …
Eq LogStrDefined in katip-0.8.8.0 · Katip.CoreShow LogStrDefined in katip-0.8.8.0 · Katip.CoreIsString LogStrDefined in katip-0.8.8.0 · Katip.CoreGeneric LogStrDefined in katip-0.8.8.0 · Katip.CoreSemigroup LogStrDefined in katip-0.8.8.0 · Katip.CoreMonoid LogStrDefined in katip-0.8.8.0 · Katip.CoreFromJSON LogStrDefined in katip-0.8.8.0 · Katip.Coretype Rep LogStr = D1 ('MetaDataDefined in katip-0.8.8.0 · Katip.Core"LogStr"
"Katip.Core"
"katip-0.8.8.0-Z7JfszSB51D3etmAJRu1J"
'True) (C1 ('MetaCons"LogStr"
'PrefixI 'True) (S1 ('MetaSel ('Just"unLogStr"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Builder)))
Shorthand for logStr
Convert any showable type into a LogStr.
Constructors
Instances5Eq, Ord, Show, FromJSON, ToJSON
Eq ThreadIdTextDefined in katip-0.8.8.0 · Katip.CoreOrd ThreadIdTextDefined in katip-0.8.8.0 · Katip.CoreShow ThreadIdTextDefined in katip-0.8.8.0 · Katip.CoreFromJSON ThreadIdTextDefined in katip-0.8.8.0 · Katip.CoreToJSON ThreadIdTextDefined in katip-0.8.8.0 · Katip.Core
This has everything each log message will contain.
Constructors
Instances7Functor, Eq, Show, Generic, FromJSON, ToJSON, …
Functor ItemDefined in katip-0.8.8.0 · Katip.CoreEq a => Eq (Item a)Defined in katip-0.8.8.0 · Katip.CoreShow a => Show (Item a)Defined in katip-0.8.8.0 · Katip.CoreGeneric (Item a)Defined in katip-0.8.8.0 · Katip.CoreFromJSON a => FromJSON (Item a)Defined in katip-0.8.8.0 · Katip.CoreToJSON a => ToJSON (Item a)Defined in katip-0.8.8.0 · Katip.Coretype Rep (Item a) = D1 ('MetaDataDefined in katip-0.8.8.0 · Katip.Core"Item"
"Katip.Core"
"katip-0.8.8.0-Z7JfszSB51D3etmAJRu1J"
'False) (C1 ('MetaCons"Item"
'PrefixI 'True) (((S1 ('MetaSel ('Just"_itemApp"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Namespace) :*: S1 ('MetaSel ('Just"_itemEnv"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Environment)) :*: (S1 ('MetaSel ('Just"_itemSeverity"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Severity) :*: (S1 ('MetaSel ('Just"_itemThread"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ThreadIdText) :*: S1 ('MetaSel ('Just"_itemHost"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HostName)))) :*: ((S1 ('MetaSel ('Just"_itemProcess"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ProcessID) :*: (S1 ('MetaSel ('Just"_itemPayload"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just"_itemMessage"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LogStr))) :*: (S1 ('MetaSel ('Just"_itemTime"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UTCTime) :*: (S1 ('MetaSel ('Just"_itemNamespace"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Namespace) :*: S1 ('MetaSel ('Just"_itemLoc"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Loc)))))))
Constructors
Instances2FromJSON, ToJSON
FromJSON ProcessIDJsDefined in katip-0.8.8.0 · Katip.CoreToJSON ProcessIDJsDefined in katip-0.8.8.0 · Katip.Core
Instances4Eq, Show, Semigroup, Monoid
Eq PayloadSelectionDefined in katip-0.8.8.0 · Katip.CoreShow PayloadSelectionDefined in katip-0.8.8.0 · Katip.CoreSemigroup PayloadSelectionDefined in katip-0.8.8.0 · Katip.CoreMonoid PayloadSelectionDefined in katip-0.8.8.0 · Katip.Core
Compares two payload selections for equivalence. With SomeKeys, ordering and duplicates are ignored.
Katip requires JSON objects to be logged as context. This typeclass provides a default instance which uses ToJSON and produces an empty object if toJSON results in any type other than object. If you have a type you want to log that produces an Array or Number for example, you'll want to write an explicit instance here. You can trivially add a ToObject instance for something with a ToJSON instance like:
instance ToObject FooInstances4ToObject
ToObject ObjectDefined in katip-0.8.8.0 · Katip.CoreToObject SimpleLogPayloadDefined in katip-0.8.8.0 · Katip.CoreToObject LogContextsDefined in katip-0.8.8.0 · Katip.MonadicToObject ()Defined in katip-0.8.8.0 · Katip.Core
Payload objects need instances of this class. LogItem makes it so
that you can have very verbose items getting logged with lots of
extra fields but under normal circumstances, if your scribe is
configured for a lower verbosity level, it will only log a
selection of those keys. Furthermore, each Scribe can be
configured with a different Verbosity level. You could even use
registerScribe, unregisterScribe, and clearScribes to at
runtime swap out your existing scribes for more verbose debugging
scribes if you wanted to.
When defining payloadKeys, don't redundantly declare the same keys for higher levels of verbosity. Each level of verbosity automatically and recursively contains all keys from the level before it.
Methods
payloadKeys :: Verbosity -> a -> PayloadSelectionList of keys in the JSON object that should be included in message.
Instances3LogItem
LogItem SimpleLogPayloadDefined in katip-0.8.8.0 · Katip.CoreLogItem LogContextsDefined in katip-0.8.8.0 · Katip.MonadicLogItem ()Defined in katip-0.8.8.0 · Katip.Core
Constructors
forall a. ToJSON a => AnyLogPayload a
Constructors
Instances5Semigroup, Monoid, ToJSON, LogItem, ToObject
Semigroup SimpleLogPayloadDefined in katip-0.8.8.0 · Katip.CoreMonoid SimpleLogPayloadDefined in katip-0.8.8.0 · Katip.CoreToJSON SimpleLogPayloadDefined in katip-0.8.8.0 · Katip.CoreLogItem SimpleLogPayloadDefined in katip-0.8.8.0 · Katip.CoreToObject SimpleLogPayloadDefined in katip-0.8.8.0 · Katip.Core
Construct a simple log from any JSON item.
Constrain payload based on verbosity. Backends should use this to automatically bubble higher verbosity levels to lower ones.
Convert log item to its JSON representation while trimming its payload based on the desired verbosity. Backends that push JSON messages should use this to obtain their payload.
Scribes are handlers of incoming items. Each registered scribe knows how to push a log item somewhere.
Guidelines for writing your own Scribe
Scribes should always take a Severity and Verbosity.
Severity is used to exclude log messages that are lower than the provided Severity. For instance, if the user passes InfoS, DebugS items should be ignored. Katip provides the permitItem utility for this. The user or the scribe may use permitAND and permitOR to further customize this filtering, even dynamically if they wish to.
Verbosity is used to select keys from the log item's payload. Each LogItem instance describes what keys should be retained for each Verbosity level. Use the payloadObject utility for extracting the keys that should be written.
Scribes provide a finalizer IO action (scribeFinalizer) that is
meant to synchronously flush any remaining writes and clean up any
resources acquired when the scribe was created. Internally, katip
keeps a buffer for each scribe's writes. When closeScribe or
closeScribes is called, that buffer stops accepting new log
messages and after the last item in its buffer is sent to liPush,
calls the finalizer. Thus, when the finalizer returns, katip can
assume that all resources are cleaned up and all log messages are
durably written.
While katip internally buffers messages per ScribeSettings, it
sends them one at a time to the scribe. Depending on the scribe
itself, it may make sense for that scribe to keep its own internal
buffer to batch-send logs if writing items one at a time is not
efficient. The scribe implementer must be sure that on
finalization, all writes are committed synchronously.
Signature of a function passed to Scribe constructor and mkScribe* functions that decides which messages to be logged. Typically filters based on Severity, but can be combined with other, custom logic with permitAND and permitOR
AND together 2 permit functions
OR together 2 permit functions
Constructors
ScribeliPush :: forall a. LogItem a => Item a -> IO ()How do we write an item to the scribe's output?
scribeFinalizer :: IO ()Provide a blocking finalizer to call when your scribe is removed. All pending writes should be flushed synchronously. If this is not relevant to your scribe, return () is fine.
scribePermitItem :: PermitFuncProvide a filtering function to allow the item to be logged, or not. It can check Severity or some string in item's body. The initial value of this is usually created from permitItem. Scribes and users can customize this by ANDing or ORing onto the default with permitAND or permitOR
Instances2Semigroup, Monoid
Semigroup ScribeDefined in katip-0.8.8.0 · Katip.CoreCombine two scribes. Publishes to the left scribe if the left would permit the item and to the right scribe if the right would permit the item. Finalizers are called in sequence from left to right.
Monoid ScribeDefined in katip-0.8.8.0 · Katip.Core
Constructors
Constructors
NewItem :: LogItem a => Item a -> WorkerMessagePoisonPill :: WorkerMessage
Should this item be logged given the user's maximum severity? Most new scribes will use this as a base for their PermitFunc
Constructors
LogEnv_logEnvHost :: HostName_logEnvPid :: ProcessID_logEnvApp :: NamespaceName of application. This will typically never change. This field gets prepended to the namespace of your individual log messages. For example, if your app is MyApp and you write a log using "logItem" and the namespace
WebServer, the final namespace will beMyApp.WebServer_logEnvEnv :: Environment_logEnvTimer :: IO UTCTimeAction to fetch the timestamp. You can use something like
AutoUpdatefor high volume logs but note that this may cause some output forms to display logs out of order. Alternatively, you could just use getCurrentTime._logEnvScribes :: Map Text ScribeHandle
initLogEnv :: NamespaceA base namespace for this application
-> EnvironmentCurrent run environment (e.g.
prodvs.devel)-> IO LogEnv
Create a reasonable default InitLogEnv. Uses an AutoUpdate which
updates the timer every 1ms. If you need even more timestamp
precision at the cost of performance, consider setting
_logEnvTimer with getCurrentTime.
Add a scribe to the list. All future log calls will go to this scribe in addition to the others. Writes will be buffered per the ScribeSettings to prevent slow scribes from slowing down logging. Writes will be dropped if the buffer fills.
Constructors
Instances2Eq, Show
Eq ScribeSettingsDefined in katip-0.8.8.0 · Katip.CoreShow ScribeSettingsDefined in katip-0.8.8.0 · Katip.Core
Reasonable defaults for a scribe. Buffer size of 4096.
Remove a scribe from the environment. This does not finalize
the scribe. This mainly only makes sense to use with something like
MonadReader's local function to temporarily disavow a single
logger for a block of code.
Unregister all scribes. Note that this is not for closing or
finalizing scribes, use closeScribes for that. This mainly only
makes sense to use with something like MonadReader's local
function to temporarily disavow any loggers for a block of code.
Finalize a scribe. The scribe is removed from the environment, its finalizer is called so that it can never be written to again and all pending writes are flushed. Note that this will throw any exceptions yoru finalizer will throw, and that LogEnv is immutable, so it will not be removed in that case.
Call this at the end of your program. This is a blocking call that stop writing to a scribe's queue, waits for the queue to empty, finalizes each scribe in the log environment and then removes it. Finalizers are all run even if one of them throws, but the exception will be re-thrown at the end.
Monads where katip logging actions can be performed. Katip is the most basic logging monad. You will typically use this directly if you either don't want to use namespaces/contexts heavily or if you want to pass in specific contexts and/or namespaces at each log site.
For something more powerful, look at the docs for KatipContext,
which keeps a namespace and merged context. You can write simple
functions that add additional namespacing and merges additional
context on the fly.
localLogEnv was added to allow for lexically-scoped modifications of the log env that are reverted when the supplied monad completes. katipNoLogging, for example, uses this to temporarily pause log outputs.
Methods
getLogEnv :: m LogEnvlocalLogEnv :: (LogEnv -> LogEnv) -> m a -> m a
Instances13Katip, …
MonadIO m => Katip (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreMonadIO m => Katip (KatipContextT m)Defined in katip-0.8.8.0 · Katip.MonadicMonadIO m => Katip (NoLoggingT m)Defined in katip-0.8.8.0 · Katip.MonadicKatip m => Katip (ResourceT m)Defined in katip-0.8.8.0 · Katip.CoreKatip m => Katip (MaybeT m)Defined in katip-0.8.8.0 · Katip.CoreKatip m => Katip (ExceptT s m)Defined in katip-0.8.8.0 · Katip.CoreKatip m => Katip (ReaderT s m)Defined in katip-0.8.8.0 · Katip.CoreKatip m => Katip (StateT s m)Defined in katip-0.8.8.0 · Katip.CoreKatip m => Katip (StateT s m)Defined in katip-0.8.8.0 · Katip.Core(Katip m, Monoid s) => Katip (WriterT s m)Defined in katip-0.8.8.0 · Katip.Core(Katip m, Monoid s) => Katip (WriterT s m)Defined in katip-0.8.8.0 · Katip.Core(Katip m, Monoid w) => Katip (RWST r w s m)Defined in katip-0.8.8.0 · Katip.Core(Katip m, Monoid w) => Katip (RWST r w s m)Defined in katip-0.8.8.0 · Katip.Core
A concrete monad you can use to run logging actions. Use this if you prefer an explicit monad transformer stack and adding layers as opposed to implementing Katip for your monad.
Instances18MonadTrans, MonadTransControl, MonadBase, MonadBaseControl, Monad, Functor, …
MonadTrans KatipTDefined in katip-0.8.8.0 · Katip.CoreMonadTransControl KatipTDefined in katip-0.8.8.0 · Katip.CoreMonadBase b m => MonadBase b (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreMonadBaseControl b m => MonadBaseControl b (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreMonad m => Monad (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreFunctor m => Functor (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreMonadFail m => MonadFail (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreApplicative m => Applicative (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreMonadIO m => MonadIO (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreMonadCatch m => MonadCatch (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreMonadMask m => MonadMask (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreMonadThrow m => MonadThrow (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreMonadUnliftIO m => MonadUnliftIO (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreMonadResource m => MonadResource (KatipT m)Defined in katip-0.8.8.0 · Katip.CoreMonadIO m => Katip (KatipT m)Defined in katip-0.8.8.0 · Katip.Core(Monad m, KatipContext m) => KatipContext (KatipT m)Defined in katip-0.8.8.0 · Katip.Monadictype StM (KatipT m) a = ComposeSt KatipT m aDefined in katip-0.8.8.0 · Katip.Coretype StT KatipT a = aDefined in katip-0.8.8.0 · Katip.Core
Execute KatipT on a log env.
Disable all scribes for the given monadic action, then restore them afterwards. Works in any Katip monad.
Log with everything, including a source code location. This is very low level and you typically can use logT in its place.
Log already constructed Item. This is the lowest level function that other log* functions use. It can be useful when implementing centralised logging services.
logF Log with full context, but without any code location.
logException :: (Katip m, LogItem a, MonadCatch m, Applicative m)=> aLog context
-> NamespaceNamespace
-> SeveritySeverity
-> m bMain action being run
-> m b
Perform an action while logging any exceptions that may occur.
Inspired by onException.
> logException () mempty ErrorS (error "foo")Log a message without any payload/context or code location.
Lift a location into an Exp.
For use when you want to include location in your logs. This will fill the 'Maybe Loc' gap in logF of this module, and relies on implicit callstacks when available (GHC > 7.8).
Loc-tagged logging when using template-haskell.
$(logT) obj mempty InfoS "Hello world"Loc-tagged logging using GHC.Stack when available.
This function does not require template-haskell as it automatically uses implicit-callstacks when the code is compiled using GHC > 7.8. Using an older version of the compiler will result in the emission of a log line without any location information, so be aware of it. Users using GHC <= 7.8 may want to use the template-haskell function logT for maximum compatibility.
logLoc obj mempty InfoS "Hello world"