Skip to content

Commit

Permalink
Convert console logs to use logger (#3141)
Browse files Browse the repository at this point in the history
* convert console logs to use logger

* relative module

* simplify import

* logger -> childLogger

* ./logging

* remove childLogger post-rebase

* undo rename
  • Loading branch information
joaquincasares authored May 31, 2022
1 parent 0efb18c commit 3fc3ddb
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
5 changes: 3 additions & 2 deletions creator-node/src/apiHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const config = require('./config')
const {
requestNotExcludedFromLogging,
getDuration,
createChildLogger
createChildLogger,
logger: genericLogger
} = require('./logging')
const { generateTimestampAndSignature } = require('./apiSigning')

Expand All @@ -19,7 +20,7 @@ module.exports.handleResponse = (func) => {
sendResponse(req, res, resp)
next()
} catch (error) {
console.error('HandleResponse', error)
genericLogger.error('HandleResponse', error)
next(error)
}
}
Expand Down
4 changes: 2 additions & 2 deletions creator-node/src/blacklistManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,12 @@ class BlacklistManager {
}
})
stream.on('end', function () {
console.log(
logger.info(
`Done deleting ${REDIS_MAP_BLACKLIST_SEGMENTCID_TO_TRACKID_KEY} entries`
)
})
stream.on('error', function (e) {
console.error(
logger.error(
`Could not delete ${REDIS_MAP_BLACKLIST_SEGMENTCID_TO_TRACKID_KEY} entries: ${e.toString()}`
)
})
Expand Down
9 changes: 5 additions & 4 deletions creator-node/src/redis.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
const config = require('./config.js')
const { logger } = require('./logging')
const Redis = require('ioredis')

const redisClient = new Redis(config.get('redisPort'), config.get('redisHost'))

const EXPIRATION = 60 * 60 * 2 // 2 hours in seconds
class RedisLock {
static async setLock(key, expiration = EXPIRATION) {
console.log(`SETTING LOCK ${key}`)
logger.info(`SETTING LOCK ${key}`)
// set allows you to set an optional expire param
return redisClient.set(key, true, 'EX', expiration)
}

static async getLock(key) {
console.log(`GETTING LOCK ${key}`)
logger.info(`GETTING LOCK ${key}`)
return redisClient.get(key)
}

static async acquireLock(key, expiration = EXPIRATION) {
console.log(`SETTING LOCK IF NOT EXISTS ${key}`)
logger.info(`SETTING LOCK IF NOT EXISTS ${key}`)
const response = await redisClient.set(key, true, 'NX', 'EX', expiration)
return !!response
}

static async removeLock(key) {
console.log(`DELETING LOCK ${key}`)
logger.info(`DELETING LOCK ${key}`)
return redisClient.del(key)
}
}
Expand Down
3 changes: 2 additions & 1 deletion creator-node/src/reqLimiter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express')
const rateLimit = require('express-rate-limit')
const config = require('./config.js')
const { logger } = require('./logging')
const RedisStore = require('rate-limit-redis')
const client = require('./redis.js')
const { verifyRequesterIsValidSP } = require('./apiSigning.js')
Expand All @@ -9,7 +10,7 @@ let endpointRateLimits = {}
try {
endpointRateLimits = JSON.parse(config.get('endpointRateLimits'))
} catch (e) {
console.error('Failed to parse endpointRateLimits!')
logger.error('Failed to parse endpointRateLimits!')
}

// Key generator for rate limiter that rate limits based on unique IP
Expand Down
2 changes: 1 addition & 1 deletion creator-node/src/routes/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const logGetCIDDecisionTree = (decisionTree, req) => {
try {
req.logger.info(`[getCID] Decision Tree: ${JSON.stringify(decisionTree)}`)
} catch (e) {
console.error(`[getCID] Decision Tree - Failed to print: ${e.message}`)
req.logger.error(`[getCID] Decision Tree - Failed to print: ${e.message}`)
}
}

Expand Down
2 changes: 1 addition & 1 deletion creator-node/src/services/TrustedNotifierManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TrustedNotifierManager {

this.trustedNotifierData = this.trustedNotifierChainData
} catch (e) {
console.error(e)
this.logError(`Failed to initialize: ${e}`)
}
}

Expand Down
2 changes: 1 addition & 1 deletion creator-node/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Utils {

static async timeout(ms, log = true) {
if (log) {
console.log(`starting timeout of ${ms}`)
genericLogger.info(`starting timeout of ${ms}`)
}
return new Promise((resolve) => setTimeout(resolve, ms))
}
Expand Down

0 comments on commit 3fc3ddb

Please sign in to comment.