forked from co-log/co-log
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[co-log#46] Move log actions that work with String to Colog.Core.IO
- Loading branch information
Showing
7 changed files
with
54 additions
and
37 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
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
module Colog.Core | ||
( module Colog.Core.Action | ||
, module Colog.Core.Class | ||
, module Colog.Core.IO | ||
, module Colog.Core.Severity | ||
) where | ||
|
||
import Colog.Core.Action | ||
import Colog.Core.Class | ||
import Colog.Core.IO | ||
import Colog.Core.Severity |
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,33 @@ | ||
module Colog.Core.IO | ||
( logStringStdout | ||
, logStringStderr | ||
, logStringHandle | ||
, withLogStringFile | ||
) where | ||
|
||
import Control.Monad.IO.Class (MonadIO, liftIO) | ||
import System.IO (Handle, IOMode( AppendMode ), hPutStrLn, stderr, withFile) | ||
import Colog.Core.Action (LogAction (..)) | ||
|
||
|
||
{- | Action that prints 'String' to stdout. -} | ||
logStringStdout :: MonadIO m => LogAction m String | ||
logStringStdout = LogAction (liftIO . putStrLn) | ||
|
||
{- | Action that prints 'String' to stderr. -} | ||
logStringStderr :: MonadIO m => LogAction m String | ||
logStringStderr = logStringHandle stderr | ||
|
||
{- | Action that prints 'String' to 'Handle'. -} | ||
logStringHandle :: MonadIO m => Handle -> LogAction m String | ||
logStringHandle handle = LogAction $ liftIO . hPutStrLn handle | ||
|
||
{- | Action that prints 'String' to file. Instead of returning 'LogAction' it's | ||
implemented in continuation-passing style because it's more efficient to open | ||
file only once at the start of the application and write to 'Handle' instead of | ||
opening file each time we need to write to it. | ||
Opens file in 'AppendMode'. | ||
-} | ||
withLogStringFile :: MonadIO m => FilePath -> (LogAction m String -> IO r) -> IO r | ||
withLogStringFile path action = withFile path AppendMode $ action . logStringHandle |
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