Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log to a chan #74

Merged
merged 4 commits into from Jan 12, 2016

Conversation

@ghost
Copy link

commented Jan 7, 2016

This change allows you to log to a channel so that you can more easily use monad-logger with a library that exposes its own logging interface (eg, haxy, http-server).

I made this change because in my program stdout/stderr weren't line-buffered, and logging messages were interlacing. The channel resolves log message ordering from threads and unChanLoggingT allows you to extract them all in one place for whatever run*LoggingT.

Here's an example of how this is used: https://gist.github.com/plredmond/22a0513972b30c14e32f

  • Not sure this is a desired direction of monad-logging. Feel free to close.
-- | Read tuples from an unbounded channel and log them, forever.
--
-- Since VERSION
unChanLoggingT :: MonadLoggerIO m => Chan (Loc, LogSource, LogLevel, LogStr) -> m ()

This comment has been minimized.

Copy link
@snoyberg

snoyberg Jan 7, 2016

Collaborator

Should this constraint be MonadLogger?

This comment has been minimized.

Copy link
@ghost

ghost Jan 7, 2016

Author

It requires MonadLoggerIO to use readChan

This comment has been minimized.

Copy link
@snoyberg

snoyberg Jan 10, 2016

Collaborator

Then it should probably be (MonadLogger m, MonadIO m). MonadLoggerIO itself seems unnecessary.

This comment has been minimized.

Copy link
@ghost

ghost Jan 12, 2016

Author

Ah yes, you're correct. Thank you!

@@ -579,6 +582,22 @@ runStderrLoggingT = (`runLoggingT` defaultOutput stderr)
runStdoutLoggingT :: MonadIO m => LoggingT m a -> m a
runStdoutLoggingT = (`runLoggingT` defaultOutput stdout)

-- | Run a block using a @MonadLogger@ instance which writes tuples to an unbounded channel.

This comment has been minimized.

Copy link
@snoyberg

snoyberg Jan 7, 2016

Collaborator

A slightly expanded documentation to explain how this plays together with the other Chan functions would be very useful, it's not immediately obvious from reading the docs/types/code.

This comment has been minimized.

Copy link
@ghost

ghost Jan 7, 2016

Author

The only other Chan function I see is withChannelLogger which implements an unrelated useful behavior (something like a temporary limited bag of log items, which are either dropped or logged depending on whether an exception demands their inclusion).

I've committed some expanded documentation on the two new functions.

screen shot 2016-01-07 at 14 44 39

This comment has been minimized.

Copy link
@snoyberg

snoyberg Jan 10, 2016

Collaborator

That looks great.

snoyberg added a commit that referenced this pull request Jan 12, 2016
@snoyberg snoyberg merged commit 7af460e into kazu-yamamoto:master Jan 12, 2016
1 check failed
1 check failed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
@snoyberg

This comment has been minimized.

Copy link
Collaborator

commented Jan 12, 2016

Merged and released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.