<div>On Sat, Apr 2, 2011 at 11:10 AM, Michael Snoyman <span dir="ltr">&lt;<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>&gt;</span> wrote:</div><div><div><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

@Sven: I agree, database level logging is a *very* nice idea. Timing<br>
could also be very useful. The former will require modifications to<br>
persistent; let&#39;s try to think about how that would work (I don&#39;t have<br>
any clear ideas immediately). For timing: we could add a nice<br>
combinator on top of the main logging functions:<br>
<br>
logTimed :: MonadIO m =&gt; (normal params) -&gt; m a -&gt; m a<br>
logTimed (normal params) action = do<br>
    begin &lt;- getCurrentTime<br>
    a &lt;- action<br>
    end &lt;- getCurrentTime<br>
    log (normal params) ++ &quot;; operation took: &quot; ++ show (end - begin)<br>
    return a<br>
<br>
@Max: I&#39;m not planning on adding a specific backend like hslogger. I&#39;d<br>
rather make a system that is flexible enough to allow a user to plug<br>
in whatever backend he/she wants. Plus, hslogger in LGPL, which I&#39;m<br>
trying to avoid in yesod-core.<br>
<br>
@Greg: I like the idea of adding source. How would you see this, just<br>
another Text argument? As for typeclass/not typeclass: the advantage<br>
to the former is that all subsites will get to piggy-back on what the<br>
master site defines. So I *definitely* think it&#39;s worthwhile.<br>
<font color="#888888"><br></font></blockquote><div> </div><div>in hslogger the source is just another string. That makes it easily extensible, but the lack of type safety worries me a bit. Maybe we just need to trust everyone to use a single canonical (Text) string for their sources. I imagine that for any source one would create a helper function that applies the source Text argument. Likewise, the default logging function for Yesod users wouldn&#39;t have a source argument.</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><font color="#888888">
Michael<br>
</font><div><div></div><div class="h5"><br>
On Sat, Apr 2, 2011 at 5:48 PM, Greg Weber &lt;<a href="mailto:greg@gregweber.info">greg@gregweber.info</a>&gt; wrote:<br>
&gt; I like Michael&#39;s straw man. The only missing aspect I see is specifying a<br>
&gt; source. hslogger has this capability. This is useful for a web framework to<br>
&gt; differentiate between database logging and request logging, etc. It can be<br>
&gt; useful for an application when it grows in size.<br>
&gt; Does logging need to be in the typeclass or does it make send to just import<br>
&gt; it?<br>
&gt; On Sat, Apr 2, 2011 at 3:22 AM, Max Cantor &lt;<a href="mailto:mxcantor@gmail.com">mxcantor@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Take a look at hslogger.  I know that another dependency is low on the<br>
&gt;&gt; &quot;things we want&quot; list, but its pretty decent.<br>
&gt;&gt;<br>
&gt;&gt; max<br>
&gt;&gt;<br>
&gt;&gt; On Apr 1, 2011, at 3:18 PM, Sven Koschnicke (GFXpro) wrote:<br>
&gt;&gt;<br>
&gt;&gt; &gt; Hello,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I would add a log level &quot;Debug&quot; which only gets printed to the log when<br>
&gt;&gt; &gt; in development mode. I also found the log output of SQL queries generated by<br>
&gt;&gt; &gt; the database layer quite helpful in development. Another thing is<br>
&gt;&gt; &gt; performance measurements, the time it takes to answer an request. These<br>
&gt;&gt; &gt; ideas are all coming from the way RoR does logging, but I found it very<br>
&gt;&gt; &gt; helpful when developing with Rails, so it should be a nice feature in Yesod,<br>
&gt;&gt; &gt; too. Here is an example:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;  Instrument Load (0.4ms)   SELECT * FROM &quot;instruments&quot; WHERE<br>
&gt;&gt; &gt; (&quot;instruments&quot;.&quot;id&quot; = 86) ORDER BY LOWER(<a href="http://instruments.name" target="_blank">instruments.name</a>)<br>
&gt;&gt; &gt; Rendered overview/_notification (2.1ms)<br>
&gt;&gt; &gt;  CACHE (0.0ms)   SELECT * FROM &quot;instruments&quot; WHERE (&quot;instruments&quot;.&quot;id&quot; =<br>
&gt;&gt; &gt; 86) ORDER BY LOWER(<a href="http://instruments.name" target="_blank">instruments.name</a>)<br>
&gt;&gt; &gt; Rendered overview/_notification (1.5ms)<br>
&gt;&gt; &gt;  CACHE (0.0ms)   SELECT * FROM &quot;instruments&quot; WHERE (&quot;instruments&quot;.&quot;id&quot; =<br>
&gt;&gt; &gt; 90) ORDER BY LOWER(<a href="http://instruments.name" target="_blank">instruments.name</a>)<br>
&gt;&gt; &gt; Rendered overview/_notification (1.4ms)<br>
&gt;&gt; &gt;  CACHE (0.0ms)   SELECT * FROM &quot;instruments&quot; WHERE (&quot;instruments&quot;.&quot;id&quot; =<br>
&gt;&gt; &gt; 62) ORDER BY LOWER(<a href="http://instruments.name" target="_blank">instruments.name</a>)<br>
&gt;&gt; &gt; Rendered overview/_notification (1.5ms)<br>
&gt;&gt; &gt;  DepotGroup Load (27.2ms)   SELECT * FROM &quot;depot_groups&quot; ORDER BY<br>
&gt;&gt; &gt; ordinal<br>
&gt;&gt; &gt; Completed in 3530ms (View: 166, DB: 2051) | 200 OK [<a href="http://localhost/" target="_blank">http://localhost/</a>]<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Sven<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On 04/01/2011 08:20 AM, Michael Snoyman wrote:<br>
&gt;&gt; &gt;&gt; Hi all,<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Hot on the heels of the decision to remove logging from WAI, I would<br>
&gt;&gt; &gt;&gt; like to add it to Yesod. I think (at least to start with), we really<br>
&gt;&gt; &gt;&gt; need two modifications: a new method in the Yesod typeclass that<br>
&gt;&gt; &gt;&gt; specifies what to do with log messages, and a function living in the<br>
&gt;&gt; &gt;&gt; Handler monad that calls that method. I do not have any strong<br>
&gt;&gt; &gt;&gt; opinions on this topic, so I would appreciate input. Here&#39;s a strawman<br>
&gt;&gt; &gt;&gt; proposal:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; data LogLevel = LevelInfo | LevelWarn | LevelError | LevelOther Text<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; class Yesod a where<br>
&gt;&gt; &gt;&gt;     messageLogger :: a -&gt;  LogLevel -&gt;  Text -&gt;  IO ()<br>
&gt;&gt; &gt;&gt;     messageLogger _ level msg = formatLogMessage level msg&gt;&gt;=<br>
&gt;&gt; &gt;&gt; Data.Text.Lazy.IO.hPutStrLn System.IO.stderr<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; formatLogMessage :: LogLevel -&gt;  Text -&gt;  IO Text<br>
&gt;&gt; &gt;&gt; formatLogMessage = ...<br>
&gt;&gt; &gt;&gt; -- print timestamp, log level, message, maybe process ID? to stderr<br>
&gt;&gt; &gt;&gt; -- make sure to expose the<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; logInfo :: MonadIO m =&gt;  Text -&gt;  GGHandler sub master m ()<br>
&gt;&gt; &gt;&gt; logInfo t = do<br>
&gt;&gt; &gt;&gt;     y&lt;  getYesod<br>
&gt;&gt; &gt;&gt;     liftIO $ messageLogger y LevelInfo t<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; ... and so on and so forth<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; This should give completely flexibility to users to send their logs<br>
&gt;&gt; &gt;&gt; anywhere (database, printer, missiles) and in whatever format they<br>
&gt;&gt; &gt;&gt; want.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Other ideas:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; * It would be nice to include file/line number information, but I&#39;m<br>
&gt;&gt; &gt;&gt; not sure how easy/possible that will be without requiring the user to<br>
&gt;&gt; &gt;&gt; manually enter CPP macros.<br>
&gt;&gt; &gt;&gt; * Actually, that was my only other idea :)<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Michael<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; web-devel mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
&gt;&gt; &gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; web-devel mailing list<br>
&gt;&gt; &gt; <a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
&gt;&gt; &gt; <a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; web-devel mailing list<br>
&gt;&gt; <a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
&gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; web-devel mailing list<br>
&gt; <a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br></div></div></div>