Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
[CBR-345] symlink points to local logfile
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Diemand <codieplusplus@apax.net>
  • Loading branch information
CodiePP committed Sep 24, 2018
1 parent ebe54f0 commit cb469f7
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions util/src/Pos/Util/Log/Rotator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,20 @@ evalRotator rotation fdesc@FileDescription{..} = do
fpath <- nameLogFile fdesc
hdl <- catchIO (openFile fpath WriteMode) $
\e -> do
prtoutException fpath e
prtoutException ("error while opening log: " ++ fpath) e
return stdout -- fallback to standard output in case of exception
hSetBuffering hdl LineBuffering

#ifdef POSIX
-- restrict symbolic links only for unix-like OS
let symLinkPath = prefixpath </> filename
let logfilePath = takeFileName fpath
-- delete a symlink if already exists and create a new
-- one that points to the correct file.
(removeFile symLinkPath) `catchIO`
\e -> case isDoesNotExistError e of
True -> putStrLn ("No other symlinks already existed. Creating a new one, named:"
++ show symLinkPath)
False -> prtoutException symLinkPath e
catchIO (createFileLink fpath symLinkPath) (\e ->
do
putStrLn $ "error while creating symlink: " ++ symLinkPath ++ " for " ++ fpath
putStrLn $ "exception: " ++ displayException e)
(removeFile symLinkPath)
`catchIO` (prtoutException ("cannot remove symlink: " ++ symLinkPath))
(createFileLink logfilePath symLinkPath)
`catchIO` (prtoutException ("cannot create symlink: " ++ symLinkPath))
#endif

-- compute next rotation time
Expand All @@ -83,10 +79,10 @@ evalRotator rotation fdesc@FileDescription{..} = do

return (hdl, maxSize, rottime)

prtoutException :: Exception e => FilePath -> e -> IO ()
prtoutException fp e = do
putStrLn $ "error while opening log @ " ++ fp
putStrLn $ "exception: " ++ displayException e
prtoutException :: Exception e => String -> e -> IO ()
prtoutException msg e = do
putStrLn msg
putStrLn ("exception: " ++ displayException e)

-- | list filenames in prefix dir which match 'filename'
listLogFiles :: FileDescription -> IO (Maybe (NonEmpty FilePath))
Expand Down

0 comments on commit cb469f7

Please sign in to comment.