From d604f19fb498a8011964cbd7148b4b4d35290481 Mon Sep 17 00:00:00 2001 From: Denis Tereshkin Date: Sun, 21 Jul 2019 12:19:24 +0700 Subject: [PATCH] More logging --- app/Main.hs | 10 ++++------ mds.conf | 4 ++-- src/ATrade/MDS/Database.hs | 3 +++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 7ecf677..ac05681 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -11,7 +11,6 @@ import ATrade.MDS.HistoryServer import Control.Concurrent import Control.Monad -import System.IO import System.Log.Formatter import System.Log.Handler (setFormatter) import System.Log.Handler.Simple @@ -44,7 +43,6 @@ initLogging = do (\x -> return $ setFormatter x (simpleLogFormatter "$utcTime\t {$loggername} <$prio> -> $msg")) - hSetBuffering stderr LineBuffering updateGlobalLogger rootLoggerName (setLevel DEBUG) updateGlobalLogger rootLoggerName (setHandlers [handler]) @@ -58,22 +56,22 @@ getConfig = do main :: IO () main = do initLogging - debugM "main" "Initializing MDS" + infoM "main" "Initializing MDS" cfg <- getConfig - debugM "main" "Config OK" + infoM "main" "Config OK" let dbConfig = DatabaseConfig { dbPath = cfgDbPath cfg, dbDatabase = cfgDbName cfg, dbUser = cfgDbAccount cfg, dbPassword = cfgDbPassword cfg } db <- initDatabase dbConfig - debugM "main" "DB initialized" + infoM "main" "DB initialized" let hsConfig = HistoryServerConfig { hspQHPEndpoint = cfgQHPEndpoint cfg, hspHAPEndpoint = cfgHAPEndpoint cfg } - debugM "main" "Starting history server" + infoM "main" "Starting history server" withContext $ \ctx -> do _ <- startHistoryServer hsConfig db ctx forever $ threadDelay 1000000 diff --git a/mds.conf b/mds.conf index d834f0e..8080332 100644 --- a/mds.conf +++ b/mds.conf @@ -3,6 +3,6 @@ "name" : "", "account" : "", "password" : "", - "qhp_endpoint" : "tcp://0.0.0.0:5595", - "hap_endpoint" : "tcp://0.0.0.0:5605" + "qhp_endpoint" : "tcp://0.0.0.0:5550", + "hap_endpoint" : "tcp://0.0.0.0:5551" } diff --git a/src/ATrade/MDS/Database.hs b/src/ATrade/MDS/Database.hs index cefe5f7..85614a0 100644 --- a/src/ATrade/MDS/Database.hs +++ b/src/ATrade/MDS/Database.hs @@ -23,6 +23,7 @@ import Data.Time.Clock.POSIX import qualified Data.Vector as V import Database.HDBC import Database.HDBC.Sqlite3 +import System.Log.Logger data TimeInterval = TimeInterval UTCTime UTCTime @@ -48,8 +49,10 @@ type MdsHandle = Connection initDatabase :: DatabaseConfig -> IO MdsHandle initDatabase config = do + infoM "DB" $ "Initializing DB" conn <- connectSqlite3 (T.unpack $ dbPath config) makeSchema conn + infoM "DB" $ "Schema updated" return conn where makeSchema conn = runRaw conn "CREATE TABLE IF NOT EXISTS bars (id SERIAL PRIMARY KEY, ticker TEXT, timestamp BIGINT, timeframe INTEGER, open NUMERIC(20, 10), high NUMERIC(20, 10), low NUMERIC(20, 10), close NUMERIC(20,10), volume BIGINT);"