From 65b17c9d18e9856c8041b9a8acc7cd5f0c48915e Mon Sep 17 00:00:00 2001 From: Efim Poberezkin <8711996+efim-poberezkin@users.noreply.github.com> Date: Thu, 20 Jan 2022 12:18:00 +0400 Subject: [PATCH] add option to enable logging (#216) Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> --- src/Simplex/Chat.hs | 16 ++++++++++------ src/Simplex/Chat/Options.hs | 8 +++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 4e4d1e41bc..c7241bf7ed 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -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 diff --git a/src/Simplex/Chat/Options.hs b/src/Simplex/Chat/Options.hs index b0544c4f35..f7504aabda 100644 --- a/src/Simplex/Chat/Options.hs +++ b/src/Simplex/Chat/Options.hs @@ -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"