Note: logging can be skipped by passing mempty as the Logger, which
discards all messages while still requiring IOE. Use runNoLog instead
if IOE is not otherwise present in the type signature.
This is useful for skipping the Log effect when it is present in the
type signature but no actual logging back-end is available, e.g. when
running pure code with runPureEff.
Start an asynchronous logger thread that consumes all queued messages once
per second.
Note: a bounded queue of size 1000000 is used internally to avoid
unrestricted memory consumption.
To make sure that the messages get written out in the presence of exceptions,
use high-level wrappers like withLogger,
Log.Backend.ElasticSearch.withElasticSearchLogger or
withBulkStdOutLogger instead of this
function directly.
Note: some messages can be lost when the main thread shuts down
without making sure that all logger threads have written out all
messages, because in that case child threads are not given a chance
to clean up by the RTS. This is apparently a feature:
https://mail.haskell.org/pipermail/haskell-cafe/2014-February/112754.html
To work around this issue, make sure that the main thread doesn't
exit until all its children have terminated. The async package
makes this easy.
Problematic example:
import Control.Concurrent.Async
main :: IO ()
main = do
logger <- Log.Backend.ElasticSearch.elasticSearchLogger
a <- Control.Concurrent.Async.async (Log.Backend.ElasticSearch.withElasticSearchLogger $ \logger ->
runLogT "main" logger defaultLogLevel $ logTrace_ "foo")
-- Main thread exits without waiting for the child
-- to finish and without giving the child a chance
-- to do proper cleanup.
Fixed example:
import Control.Concurrent.Async
main :: IO ()
main = do
logger <- Log.Backend.ElasticSearch.elasticSearchLogger
a <- Control.Concurrent.Async.async (Log.Backend.ElasticSearch.withElasticSearchLogger $ \logger ->
runLogT "main" logger defaultLogLevel $ logTrace_ "foo")
Control.Concurrent.Async.wait a
-- Main thread waits for the child to finish, giving
-- it a chance to shut down properly. This works even
-- in the presence of exceptions in the child thread.
Return an IO action that logs messages using the current MonadLog
context. Useful for interfacing with libraries such as aws or amazonka
that accept logging callbacks operating in IO.
Note that in the case of asynchronous/bulk loggers runLogT
doesn't guarantee that all messages are actually written to the log
once it finishes. Use withPGLogger or withElasticSearchLogger
for that.
Represents the family of monads with logging capabilities. Each
MonadLog carries with it some associated state (the logging
environment) that can be modified locally with localData and
localDomain.
An object used for communication with a logger thread that
outputs LogMessages using e.g. PostgreSQL, Elasticsearch or
stdout (depending on the back-end chosen).
Instances2Semigroup, Monoid
SemigroupLoggerDefined in log-base-0.12.1.0 · Log.Internal.Logger
MonoidLoggerDefined in log-base-0.12.1.0 · Log.Internal.Logger
This is the simplest representation of UTC.
It consists of the day number, and a time offset from midnight.
Note that if a day has a leap second added to it, it will have 86401 seconds.
Instances17Eq, Data, Ord, Read, Show, Generic, …
EqUTCTimeDefined in time-1.15 · Data.Time.Clock.Internal.UTCTime
DataUTCTimeDefined in time-1.15 · Data.Time.Clock.Internal.UTCTime
OrdUTCTimeDefined in time-1.15 · Data.Time.Clock.Internal.UTCTime
ReadUTCTimeDefined in time-1.15 · Data.Time.Format.Parse · orphan
ShowUTCTimeDefined in time-1.15 · Data.Time.LocalTime.Internal.ZonedTime · orphan
GenericUTCTimeDefined in time-1.15 · Data.Time.Clock.Internal.UTCTime
NFDataUTCTimeDefined in time-1.15 · Data.Time.Clock.Internal.UTCTime
HashableUTCTimeDefined in time-compat-1.9.9 · Data.Time.Orphans · orphan
FormatTimeUTCTimeDefined in time-1.15 · Data.Time.Format.Format.Instances · orphan
ParseTimeUTCTimeDefined in time-1.15 · Data.Time.Format.Parse.Instances · orphan
ISO8601UTCTimeDefined in time-1.15 · Data.Time.Format.ISO8601
yyyy-mm-ddThh:mm:ss[.ss]Z [ISO 8601:2004(E) sec. 4.3.2 extended format]
FromJSONUTCTimeDefined in aeson-2.3.2.0 · Data.Aeson.Types.FromJSON