-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement log file backend * Add logs directory contents to .gitignore * Lint * Use Cabal-syntax everywhere * Remove CoverageReport
- Loading branch information
Showing
9 changed files
with
48 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,4 @@ pgdata/ | |
.DS_Store | ||
tags.lock | ||
cabal.project.local | ||
|
||
logs/* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Log.Backend.File where | ||
|
||
import qualified Data.Aeson as Aeson | ||
import qualified Data.ByteString.Char8 as BS | ||
import qualified Data.ByteString.Lazy as BSL | ||
import Data.Kind (Type) | ||
import Effectful | ||
import qualified Effectful.Log.Logger as Log | ||
import GHC.Generics (Generic) | ||
import Log (Logger) | ||
import System.IO (stdout) | ||
|
||
data FileBackendConfig = FileBackendConfig | ||
{ destinationFile :: FilePath | ||
} | ||
deriving stock (Eq, Ord, Show, Generic) | ||
|
||
withJSONFileBackend :: | ||
forall (es :: [Effect]) (a :: Type). | ||
IOE :> es => | ||
FileBackendConfig -> | ||
(Logger -> Eff es a) -> | ||
Eff es a | ||
withJSONFileBackend FileBackendConfig{destinationFile} action = do | ||
liftIO $ BS.hPutStrLn stdout $ BS.pack $ "Redirecting logs to " <> destinationFile | ||
logger <- Log.mkLogger "file-json" $ \msg -> liftIO $ do | ||
BS.appendFile destinationFile (BSL.toStrict $ Aeson.encode msg) | ||
Log.withLogger logger action |