From e32796391284df971d77d389d466631f66d37812 Mon Sep 17 00:00:00 2001 From: Andrew Martin Date: Tue, 30 Jun 2015 17:02:33 -0400 Subject: [PATCH 1/2] Don't show source location for logs that don't have that information --- yesod-core/Yesod/Core/Class/Yesod.hs | 36 ++++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/yesod-core/Yesod/Core/Class/Yesod.hs b/yesod-core/Yesod/Core/Class/Yesod.hs index 88379b59..70b7266f 100644 --- a/yesod-core/Yesod/Core/Class/Yesod.hs +++ b/yesod-core/Yesod/Core/Class/Yesod.hs @@ -615,7 +615,14 @@ asyncHelper render scripts jscript jsLoc = Nothing -> Nothing Just j -> Just $ jelper j --- | Default formatting for log messages. +-- | Default formatting for log messages. When you use +-- the template haskell logging functions for to log with information +-- about the source location, that information will be appended to +-- the end of the log. When you use the non-TH logging functions, +-- like 'logDebugN', this function does not include source +-- information. This currently works by checking to see if the +-- package name is the string \"\\". This is a hack, +-- but it removes some of the visual clutter from non-TH logs. -- -- Since 1.4.10 formatLogMessage :: IO ZonedDate @@ -626,20 +633,23 @@ formatLogMessage :: IO ZonedDate -> IO LogStr formatLogMessage getdate loc src level msg = do now <- getdate - return $ - toLogStr now `mappend` - " [" `mappend` - (case level of + let sourceSuffix = if loc_package loc == "" then "" else mempty + `mappend` " @(" + `mappend` toLogStr (fileLocationToString loc) + `mappend` ")" + return $ mempty + `mappend` toLogStr now + `mappend` " [" + `mappend` (case level of LevelOther t -> toLogStr t - _ -> toLogStr $ drop 5 $ show level) `mappend` - (if T.null src + _ -> toLogStr $ drop 5 $ show level) + `mappend` (if T.null src then mempty - else "#" `mappend` toLogStr src) `mappend` - "] " `mappend` - msg `mappend` - " @(" `mappend` - toLogStr (fileLocationToString loc) `mappend` - ")\n" + else "#" `mappend` toLogStr src) + `mappend` "] " + `mappend` msg + `mappend` sourceSuffix + `mappend` "\n" -- | Customize the cookies used by the session backend. You may -- use this function on your definition of 'makeSessionBackend'. From e37ccee3d7205dbddf77c16f1d6cff8ca108cd17 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 30 Jun 2015 18:30:24 -0400 Subject: [PATCH 2/2] Use a let binding for greater clarity --- yesod-core/Yesod/Core/Class/Yesod.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/yesod-core/Yesod/Core/Class/Yesod.hs b/yesod-core/Yesod/Core/Class/Yesod.hs index 70b7266f..14224af8 100644 --- a/yesod-core/Yesod/Core/Class/Yesod.hs +++ b/yesod-core/Yesod/Core/Class/Yesod.hs @@ -633,10 +633,6 @@ formatLogMessage :: IO ZonedDate -> IO LogStr formatLogMessage getdate loc src level msg = do now <- getdate - let sourceSuffix = if loc_package loc == "" then "" else mempty - `mappend` " @(" - `mappend` toLogStr (fileLocationToString loc) - `mappend` ")" return $ mempty `mappend` toLogStr now `mappend` " [" @@ -650,6 +646,11 @@ formatLogMessage getdate loc src level msg = do `mappend` msg `mappend` sourceSuffix `mappend` "\n" + where + sourceSuffix = if loc_package loc == "" then "" else mempty + `mappend` " @(" + `mappend` toLogStr (fileLocationToString loc) + `mappend` ")" -- | Customize the cookies used by the session backend. You may -- use this function on your definition of 'makeSessionBackend'.