add option to enable logging (#216)

Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
Efim Poberezkin 2022-01-20 12:18:00 +04:00 committed by GitHub
parent aef159b097
commit 65b17c9d18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -127,12 +127,16 @@ logCfg :: LogConfig
logCfg = LogConfig {lc_file = Nothing, lc_stderr = True}
simplexChat :: WithTerminal t => ChatConfig -> ChatOpts -> t -> IO ()
simplexChat cfg opts t =
-- setLogLevel LogInfo -- LogError
-- withGlobalLogging logCfg $ do
initializeNotifications
>>= newChatController cfg opts t
>>= runSimplexChat
simplexChat cfg opts@ChatOpts {logging} t
| logging = do
setLogLevel LogInfo -- LogError
withGlobalLogging logCfg initRun
| otherwise = initRun
where
initRun =
initializeNotifications
>>= newChatController cfg opts t
>>= runSimplexChat
newChatController :: WithTerminal t => ChatConfig -> ChatOpts -> t -> (Notification -> IO ()) -> IO ChatController
newChatController config@ChatConfig {agentConfig = cfg, dbPoolSize, tbqSize} ChatOpts {dbFile, smpServers} t sendNotification = do

View File

@ -15,7 +15,8 @@ import System.FilePath (combine)
data ChatOpts = ChatOpts
{ dbFile :: String,
smpServers :: NonEmpty SMPServer
smpServers :: NonEmpty SMPServer,
logging :: Bool
}
chatOpts :: FilePath -> Parser ChatOpts
@ -45,6 +46,11 @@ chatOpts appDir =
]
)
)
<*> switch
( long "log"
<> short 'l'
<> help "Enable logging"
)
where
defaultDbFilePath = combine appDir "simplex_v1"