Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

[#345] logging configuration for logging to file #350

Merged
merged 10 commits into from
Nov 13, 2019
24 changes: 23 additions & 1 deletion cardano-launcher/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import Options.Applicative (Parser, ParserInfo, auto, execParser,
fullDesc, header, help, helper, info,
long, metavar, option, optional, progDesc)

import qualified Cardano.BM.Configuration.Model as CM
import Cardano.BM.Data.Output
import Cardano.BM.Data.Rotation
import Cardano.BM.Setup (withTrace)
import qualified Cardano.BM.Trace as Trace
import Cardano.BM.Tracing
Expand Down Expand Up @@ -102,7 +105,6 @@ main = silence $ do
-- Otherwise run the real deal, the real function.
runDefaultUpdateProcess filePath arguments


logConfig <- defaultConfigStdout

-- A safer way to close the tracing.
Expand All @@ -129,6 +131,26 @@ main = silence $ do
throwM $ LauncherOptionsError (show err)
Right lo -> pure lo

-- the log output path (TODO: get base path from configuration)
let logfilepath = lologsPrefix launcherOptions <> "Logs/launcher"

scribes0 <- CM.getSetupScribes logConfig
CM.setSetupScribes logConfig $ scribes0 <>
[ScribeDefinition {
scName = toS logfilepath,
scFormat = ScText,
scKind = FileSK,
scPrivacy = ScPublic,
scRotation = Just $ RotationParameters
{
rpLogLimitBytes = 10000000,
rpMaxAgeHours = 24,
rpKeepFilesNum = 3
}
}]
CM.setDefaultScribes logConfig [ "StdoutSK::text"
, "FileSK::" <> toS logfilepath ]

let lockFile = loStateDir launcherOptions <> "/daedalus_lockfile"
Trace.logNotice baseTrace $ "Locking file so that multiple applications won't run at same time"
-- Check if it's locked or not. Will throw an exception if the
Expand Down
3 changes: 3 additions & 0 deletions cardano-launcher/src/Cardano/Shell/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ data LauncherOptions = LauncherOptions
, loWorkingDirectory :: !FilePath
, loStateDir :: !FilePath
-- On WIN it should set this directory as current.
, lologsPrefix :: !FilePath
} deriving (Show, Generic)

instance FromJSON LauncherOptions where
Expand All @@ -63,6 +64,7 @@ instance FromJSON LauncherOptions where
tlsPath <- o .:? "tlsPath"
workingDir <- o .: "workingDir"
stateDir <- o .: "stateDir"
logsPrefix <- o .: "logsPrefix"

pure $ LauncherOptions
configuration
Expand All @@ -73,6 +75,7 @@ instance FromJSON LauncherOptions where
daedalusBin
workingDir
stateDir
logsPrefix

-- | Configuration yaml file location and the key to use. The file should
-- parse to a MultiConfiguration and the 'cfoKey' should be one of the keys
Expand Down