Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert console logs to use logger #3141

Merged
merged 7 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed on remote-dev.

`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}`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed on remote-dev

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