First of all, this is my first experience ever with logs; and i don't really know what a scheduler is, only heard about them.
Now, as a first approach, i want to make a file with only important logs (WARNING or above), and daily files (like 2017-7-20.log) for all possible logged messages that day.
This is my code atm:
module Utilities.Loggers where
import System.Log.Logger
-- import System.Log.Handler.Syslog (TODO: remote logs)
import System.Log.Handler.Simple
import System.Log.Handler (LogHandler, setFormatter)
import System.Log.Formatter
import Data.Time
import GHC.IO.Handle (Handle)
--------------------------------------------
importantLogsPath :: FilePath
importantLogsPath = "app/logs/prioritary.log"
logsFolder :: FilePath
logsFolder = "app/logs/allLogs/"
defaultFormat :: LogFormatter a
defaultFormat = simpleLogFormatter "[$utcTime : $tid : $loggername : $prio] $msg"
applyFormat :: LogHandler a => a -> a
applyFormat h = setFormatter h defaultFormat
--------------------------------------------
prioritaryHandler :: IO (GenericHandler Handle)
prioritaryHandler = applyFormat <$> prioritaryHandler'
where
prioritaryHandler' = fileHandler importantLogsPath WARNING
todaysHandler :: UTCTime -> IO (GenericHandler Handle)
todaysHandler = (applyFormat <$>) . todaysHandler'
where
todaysHandler' time = fileHandler (mkPath time) DEBUG
mkPath time = logsFolder ++ show (utctDay time) ++ ".log"
--------------------------------------------
initLogger :: IO ()
initLogger = do
h1 <- prioritaryHandler
timeNow <- getCurrentTime
h2 <- todaysHandler timeNow
updateGlobalLogger "MyApp" (setHandlers [h2,h1])
If i understood correctly, each handle "listens" for possible messages that are above its priority level (daily handles have the DEBUG priority, the lowest possible, so they should catch every message)
So i need something that everyday at 00:00 utctime removes the handle for the passing day and adds the handle for the new day, right?
Also i'm a bit puzzled with the naming issues for loggers/messages, but that's just me (althout any insight will be welcome)
Edit: it's a web server