logging tidy up

This commit is contained in:
Steve Waterworth
2019-02-06 10:04:52 +00:00
parent a5375311a3
commit 7a76c9db36
4 changed files with 13 additions and 11 deletions

2
.env
View File

@@ -1,3 +1,3 @@
# environment file for docker-compose
REPO=robotshop
TAG=0.4.1
TAG=0.4.2

View File

@@ -135,7 +135,9 @@ publisher = Publisher(app.logger)
if __name__ == "__main__":
sh = logging.StreamHandler(sys.stdout)
sh.setLevel(logging.INFO)
app.logger.addHandler(sh)
fmt = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#sh.setFormatter(fmt)
#app.logger.addHandler(sh)
app.logger.setLevel(logging.INFO)
app.logger.info('Payment gateway {}'.format(PAYMENT_GATEWAY))
port = int(os.getenv("SHOP_PAYMENT_PORT", "8080"))

View File

@@ -1,5 +1,5 @@
{
"require": {
"monolog/monolog": "1.0.*"
"monolog/monolog": "^1.24.0"
}
}

View File

@@ -83,11 +83,11 @@ class RatingsAPI extends API {
return array('avg_rating' => 0, 'rating_count' => 0);
}
} else {
$this->logger->err('failed to query data');
$this->logger->error('failed to query data');
throw new Exception('Failed to query data', 500);
}
} else {
$this->logger->err('database connection error');
$this->logger->error('database connection error');
throw new Exception('Database connection error', 500);
}
}
@@ -97,11 +97,11 @@ class RatingsAPI extends API {
if($db) {
$stmt = $db->prepare('update ratings set avg_rating = ?, rating_count = ? where sku = ?');
if(! $stmt->execute(array($score, $count, $sku))) {
$this->logger->err('failed to update rating');
$this->logger->error('failed to update rating');
throw new Exception('Failed to update data', 500);
}
} else {
$this->logger->err('database connection error');
$this->logger->error('database connection error');
throw new Exception('Database connection error', 500);
}
}
@@ -111,11 +111,11 @@ class RatingsAPI extends API {
if($db) {
$stmt = $db->prepare('insert into ratings(sku, avg_rating, rating_count) values(?, ?, ?)');
if(! $stmt->execute(array($sku, $score, 1))) {
$this->logger->err('failed to insert data');
$this->logger->error('failed to insert data');
throw new Exception('Failed to insert data', 500);
}
} else {
$this->logger->err('database connection error');
$this->logger->error('database connection error');
throw new Exception('Database connection error', 500);
}
}
@@ -133,7 +133,7 @@ class RatingsAPI extends API {
$db = new PDO($dsn, 'ratings', 'iloveit', $opt);
} catch (PDOException $e) {
$msg = $e->getMessage();
$this->logger->err("Database error $msg");
$this->logger->error("Database error $msg");
$db = false;
}
@@ -153,7 +153,7 @@ class RatingsAPI extends API {
$data = curl_exec($curl);
if(! $data) {
$this->logger->err('failed to connect to catalogue');
$this->logger->error('failed to connect to catalogue');
throw new Exception('Failed to connect to catalogue', 500);
}
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);