logger
logger copied to clipboard
Rotating while live?
Hello,
Just want to check if it is possible for the logs to be rotated while live?
----------------------------------------
-- my usage of fast-logger
---------------------------------------
-- 1 MiB = 1 mebibyte = 1,0242 bytes = 1,048,576 bytes
-- 100 MiB = 1,048,576 * 100 bytes
logger :: Text -> TChan Text -> IO ()
logger logPrefix chan =
do filename <- logFilename logPrefix
let fileLogSpec =
FileLogSpec (cs filename)
104857600
10
withFastLogger (LogFile fileLogSpec 1048576)
(readAndLog fileLogSpec chan)
readAndLog
:: FileLogSpec -> TChan Text -> (LogStr -> IO a) -> IO ()
readAndLog fileLogSpec chan f =
atomically (readTChan chan) >>= f . (toLogStr :: Text -> LogStr) >>
readAndLog fileLogSpec chan f
--------------------------------------------------
-- not sure how to use this. If I use it in readAndLog, it gives this
-- message
-- exe: /tmp/<filename.log>: openFile: resource busy (file is locked)
checkAndRotate :: FileLogSpec -> IO ()
checkAndRotate spec =
do size <- getFileSize (log_file spec)
when (size > log_file_size spec)
(rotate spec)
getFileSize
:: BasicPrelude.FilePath -> IO Integer
getFileSize path = withFile path ReadMode hFileSize
I have a log running process and it would be nice if fast-logger can auto-rotate the logs on reaching a certain size. The log filehandle is locked by fast-logger and I cannot read the size of the log file while fast-logger is running.
Thanks
Hello! Thanks for providing fast-logger!
I was also bumping into this issue. I expected that the file would be rotated live, but it seems this is not the case. I have a long-running process and would like the log files be split up into smaller chunks. Is this possible?