Skip to content

Commit

Permalink
Add thread to logs
Browse files Browse the repository at this point in the history
  • Loading branch information
tbidne committed May 12, 2024
1 parent 114b7b9 commit 9b5b474
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/tbidne/monad-effects.git
tag: 1725ed9812a21c7d3d32f5becc01a2eaab76cc9f
tag: c02f58fcd475e447b69094456a186fd613dea930
subdir:
lib/effects-env
lib/effects-exceptions
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/Navi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import DBus.Notify (UrgencyLevel (Critical, Normal))
import Data.Text qualified as T
import Effects.Concurrent.Async qualified as Async
import Effects.Concurrent.STM (flushTBQueueA)
import Effects.Concurrent.Thread (sleep)
import Effects.Concurrent.Thread (MonadThread (labelThread, myThreadId), sleep)
import Effects.LoggerNS
( MonadLoggerNS,
addNamespace,
Expand Down Expand Up @@ -142,6 +142,8 @@ processEvent ::
AnyEvent ->
m Void
processEvent (MkAnyEvent event) = addNamespace (fromString $ unpack name) $ do
tid <- myThreadId
labelThread tid (fromString $ unpack name)
let pi = event ^. (#pollInterval % #unPollInterval)
forever $ do
$(logInfo) ("Checking " <> name)
Expand Down
4 changes: 3 additions & 1 deletion src/Navi/NaviT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ instance
logQueue <- asks getLogQueue
logLevel <- asks (view #logLevel . getLogEnv)
when (logLevel <= lvl) $ do
formatted <- formatLog (defaultLogFormatter loc) lvl msg
formatted <- formatLog formatter lvl msg
writeTBQueueA logQueue formatted
where
formatter = set' #threadLabel True (defaultLogFormatter loc)

instance
( HasLogEnv env,
Expand Down

0 comments on commit 9b5b474

Please sign in to comment.