katip-0.8.5.0: A structured logging framework.

Safe HaskellNone
LanguageHaskell2010

Katip.Scribes.Handle

Synopsis

Documentation

data ColorStrategy Source #

Constructors

ColorLog Bool

Whether to use color control chars in log output

ColorIfTerminal

Color if output is a terminal

mkHandleScribe :: ColorStrategy -> Handle -> PermitFunc -> Verbosity -> IO Scribe Source #

Logs to a file handle such as stdout, stderr, or a file. Contexts and other information will be flattened out into bracketed fields. For example:

[2016-05-11 21:01:15][MyApp][Info][myhost.example.com][PID 1724][ThreadId 1154][main:Helpers.Logging Helpers/Logging.hs:32:7] Started
[2016-05-11 21:01:15][MyApp.confrabulation][Debug][myhost.example.com][PID 1724][ThreadId 1154][confrab_factor:42.0][main:Helpers.Logging Helpers/Logging.hs:41:9] Confrabulating widgets, with extra namespace and context
[2016-05-11 21:01:15][MyApp][Info][myhost.example.com][PID 1724][ThreadId 1154][main:Helpers.Logging Helpers/Logging.hs:43:7] Namespace and context are back to normal

Returns the newly-created Scribe. The finalizer flushes the handle. Handle mode is set to LineBuffering automatically.

mkHandleScribeWithFormatter :: (forall a. LogItem a => ItemFormatter a) -> ColorStrategy -> Handle -> PermitFunc -> Verbosity -> IO Scribe Source #

Logs to a file handle such as stdout, stderr, or a file. Takes a custom ItemFormatter that can be used to format Item as needed.

Returns the newly-created Scribe. The finalizer flushes the handle. Handle mode is set to LineBuffering automatically.

mkFileScribe :: FilePath -> PermitFunc -> Verbosity -> IO Scribe Source #

A specialization of mkHandleScribe that takes a FilePath instead of a Handle. It is responsible for opening the file in AppendMode and will close the file handle on 'closeScribe'/'closeScribes'. Does not do log coloring. Sets handle to LineBuffering mode.

type ItemFormatter a = Bool -> Verbosity -> Item a -> Builder Source #

A custom ItemFormatter for logging Items. Takes a Value indicating whether to colorize the output, Verbosity of output, and an Item to format.

See bracketFormat and jsonFormat for examples.

formatItem :: LogItem a => ItemFormatter a Source #

Deprecated: Use bracketFormat instead

bracketFormat :: LogItem a => ItemFormatter a Source #

A traditional bracketed log format. Contexts and other information will be flattened out into bracketed fields. For example:

[2016-05-11 21:01:15][MyApp][Info][myhost.example.com][PID 1724][ThreadId 1154][main:Helpers.Logging Helpers/Logging.hs:32:7] Started
[2016-05-11 21:01:15][MyApp.confrabulation][Debug][myhost.example.com][PID 1724][ThreadId 1154][confrab_factor:42.0][main:Helpers.Logging Helpers/Logging.hs:41:9] Confrabulating widgets, with extra namespace and context
[2016-05-11 21:01:15][MyApp][Info][myhost.example.com][PID 1724][ThreadId 1154][main:Helpers.Logging Helpers/Logging.hs:43:7] Namespace and context are back to normal

jsonFormat :: LogItem a => ItemFormatter a Source #

Logs items as JSON. This can be useful in circumstances where you already have infrastructure that is expecting JSON to be logged to a standard stream or file. For example:

{"at":"2018-10-02T21:50:30.4523848Z","env":"production","ns":["MyApp"],"data":{},"app":["MyApp"],"msg":"Started","pid":"10456","loc":{"loc_col":9,"loc_pkg":"main","loc_mod":"Helpers.Logging","loc_fn":"Helpers\\Logging.hs","loc_ln":44},"host":"myhost.example.com","sev":"Info","thread":"ThreadId 139"}
{"at":"2018-10-02T21:50:30.4523848Z","env":"production","ns":["MyApp","confrabulation"],"data":{"confrab_factor":42},"app":["MyApp"],"msg":"Confrabulating widgets, with extra namespace and context","pid":"10456","loc":{"loc_col":11,"loc_pkg":"main","loc_mod":"Helpers.Logging","loc_fn":"Helpers\\Logging.hs","loc_ln":53},"host":"myhost.example.com","sev":"Debug","thread":"ThreadId 139"}
{"at":"2018-10-02T21:50:30.4523848Z","env":"production","ns":["MyApp"],"data":{},"app":["MyApp"],"msg":"Namespace and context are back to normal","pid":"10456","loc":{"loc_col":9,"loc_pkg":"main","loc_mod":"Helpers.Logging","loc_fn":"Helpers\\Logging.hs","loc_ln":55},"host":"myhost.example.com","sev":"Info","thread":"ThreadId 139"}

colorBySeverity :: Bool -> Severity -> Text -> Text Source #

Color a text message based on Severity. ErrorS and more severe errors are colored red, WarningS is colored yellow, and all other messages are rendered in the default color.

ioLogEnv :: PermitFunc -> Verbosity -> IO LogEnv Source #

Provides a simple log environment with 1 scribe going to stdout. This is a decent example of how to build a LogEnv and is best for scripts that just need a quick, reasonable set up to log to stdout.