Browse Source

More logging

master
Denis Tereshkin 6 years ago
parent
commit
d604f19fb4
  1. 10
      app/Main.hs
  2. 4
      mds.conf
  3. 3
      src/ATrade/MDS/Database.hs

10
app/Main.hs

@ -11,7 +11,6 @@ import ATrade.MDS.HistoryServer
import Control.Concurrent import Control.Concurrent
import Control.Monad import Control.Monad
import System.IO
import System.Log.Formatter import System.Log.Formatter
import System.Log.Handler (setFormatter) import System.Log.Handler (setFormatter)
import System.Log.Handler.Simple import System.Log.Handler.Simple
@ -44,7 +43,6 @@ initLogging = do
(\x -> return $ (\x -> return $
setFormatter x (simpleLogFormatter "$utcTime\t {$loggername} <$prio> -> $msg")) setFormatter x (simpleLogFormatter "$utcTime\t {$loggername} <$prio> -> $msg"))
hSetBuffering stderr LineBuffering
updateGlobalLogger rootLoggerName (setLevel DEBUG) updateGlobalLogger rootLoggerName (setLevel DEBUG)
updateGlobalLogger rootLoggerName (setHandlers [handler]) updateGlobalLogger rootLoggerName (setHandlers [handler])
@ -58,22 +56,22 @@ getConfig = do
main :: IO () main :: IO ()
main = do main = do
initLogging initLogging
debugM "main" "Initializing MDS" infoM "main" "Initializing MDS"
cfg <- getConfig cfg <- getConfig
debugM "main" "Config OK" infoM "main" "Config OK"
let dbConfig = DatabaseConfig { dbPath = cfgDbPath cfg, let dbConfig = DatabaseConfig { dbPath = cfgDbPath cfg,
dbDatabase = cfgDbName cfg, dbDatabase = cfgDbName cfg,
dbUser = cfgDbAccount cfg, dbUser = cfgDbAccount cfg,
dbPassword = cfgDbPassword cfg } dbPassword = cfgDbPassword cfg }
db <- initDatabase dbConfig db <- initDatabase dbConfig
debugM "main" "DB initialized" infoM "main" "DB initialized"
let hsConfig = HistoryServerConfig { let hsConfig = HistoryServerConfig {
hspQHPEndpoint = cfgQHPEndpoint cfg, hspQHPEndpoint = cfgQHPEndpoint cfg,
hspHAPEndpoint = cfgHAPEndpoint cfg } hspHAPEndpoint = cfgHAPEndpoint cfg }
debugM "main" "Starting history server" infoM "main" "Starting history server"
withContext $ \ctx -> do withContext $ \ctx -> do
_ <- startHistoryServer hsConfig db ctx _ <- startHistoryServer hsConfig db ctx
forever $ threadDelay 1000000 forever $ threadDelay 1000000

4
mds.conf

@ -3,6 +3,6 @@
"name" : "", "name" : "",
"account" : "", "account" : "",
"password" : "", "password" : "",
"qhp_endpoint" : "tcp://0.0.0.0:5595", "qhp_endpoint" : "tcp://0.0.0.0:5550",
"hap_endpoint" : "tcp://0.0.0.0:5605" "hap_endpoint" : "tcp://0.0.0.0:5551"
} }

3
src/ATrade/MDS/Database.hs

@ -23,6 +23,7 @@ import Data.Time.Clock.POSIX
import qualified Data.Vector as V import qualified Data.Vector as V
import Database.HDBC import Database.HDBC
import Database.HDBC.Sqlite3 import Database.HDBC.Sqlite3
import System.Log.Logger
data TimeInterval = TimeInterval UTCTime UTCTime data TimeInterval = TimeInterval UTCTime UTCTime
@ -48,8 +49,10 @@ type MdsHandle = Connection
initDatabase :: DatabaseConfig -> IO MdsHandle initDatabase :: DatabaseConfig -> IO MdsHandle
initDatabase config = do initDatabase config = do
infoM "DB" $ "Initializing DB"
conn <- connectSqlite3 (T.unpack $ dbPath config) conn <- connectSqlite3 (T.unpack $ dbPath config)
makeSchema conn makeSchema conn
infoM "DB" $ "Schema updated"
return conn return conn
where 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);" 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);"

Loading…
Cancel
Save