use loglevel module for logging

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2018-12-20 22:17:13 +01:00
parent 8c56210812
commit 07145a6e92
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
5 changed files with 15 additions and 6 deletions

View File

@ -7,7 +7,8 @@ RUN yarn install --production
COPY dist/ ./
ENV LISTEN_PORT=8000 \
ENV LOG_LEVEL=INFO \
LISTEN_PORT=8000 \
DB_SAVE_INTERVAL=5000 \
DB_PATH='/tmp/builds.db' \
GH_TOKEN='' \

View File

@ -14,6 +14,7 @@
"koa-json": "^2.0.2",
"koa-json-error": "^3.1.2",
"koa-logger": "^3.2.0",
"loglevel": "^1.6.1",
"lokijs": "^1.5.5"
},
"devDependencies": {

View File

@ -1,3 +1,4 @@
import log from 'loglevel'
import Joi from 'joi'
import Loki from 'lokijs'
import schema from './schema'
@ -49,12 +50,12 @@ class Builds {
}
async addBuild (pr, build) {
console.log(`Storing build for PR-${pr}: #${build.id} for ${build.platform}`)
log.info(`Storing build for PR-${pr}: #${build.id} for ${build.platform}`)
return await this.builds.insert({pr, ...build})
}
async addComment (pr, comment_id) {
console.log(`Storing comment for PR-${pr}: ${comment_id}`)
log.info(`Storing comment for PR-${pr}: ${comment_id}`)
return await this.comments.insert({pr, comment_id})
}

View File

@ -1,3 +1,4 @@
import log from 'loglevel'
import Handlebars from 'handlebars'
import template from './template'
@ -45,7 +46,7 @@ class Comments {
}
async postComment (pr) {
console.log(`Creating comment in PR-${pr}`)
log.info(`Creating comment in PR-${pr}`)
const body = await this.renderComment(pr)
const rval = await this.gh.issues.createComment({
owner: this.owner,
@ -57,7 +58,7 @@ class Comments {
}
async updateComment (pr, comment_id) {
console.log(`Updating comment in PR-${pr}`)
log.info(`Updating comment in PR-${pr}`)
const body = await this.renderComment(pr)
const rval = await this.gh.issues.updateComment({
owner: this.owner,

View File

@ -1,11 +1,13 @@
import log from 'loglevel'
import Logger from 'koa-logger'
import Octokit from '@octokit/rest'
import App from './app'
import Octokit from '@octokit/rest'
import Builds from './builds'
import Comments from './comments'
/* DEFAULTS */
const LOG_LEVEL = process.env.LOG_LEVEL || 'INFO'
const LISTEN_PORT = process.env.LISTEN_PORT || 8000
const GH_TOKEN = process.env.GH_TOKEN || null
const GH_REPO_OWNER = process.env.GH_REPO_OWNER || 'status-im'
@ -13,6 +15,9 @@ const GH_REPO_NAME = process.env.GH_REPO_NAME || 'status-react'
const DB_PATH = process.env.DB_PATH || '/tmp/builds.db'
const DB_SAVE_INTERVAL = process.env.DB_SAVE_INTERVAL || 5000
/* set the logging level (TRACE, DEBUG, INFO, WARN, ERROR, SILENT) */
log.setDefaultLevel(log.levels[LOG_LEVEL])
/* to store current builds bound to a PR */
const builds = new Builds(DB_PATH, DB_SAVE_INTERVAL)