Skip to content

Commit

Permalink
migrate to pino
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohansebas committed Dec 16, 2024
1 parent b62b7f1 commit 7c73879
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ project
try {
await runAddProjectCommand(knex, options)
} catch (error) {
logger.error('Error adding project:', error.message)
logger.error(error)
process.exit(1)
} finally {
await knex.destroy()
Expand All @@ -38,7 +38,7 @@ workflow
try {
await runWorkflowCommand(knex, options)
} catch (error) {
logger.error('Error running workflow:', error.message)
logger.error(error)
process.exit(1)
} finally {
await knex.destroy()
Expand All @@ -62,7 +62,7 @@ check
try {
await listCheckCommand(knex, options)
} catch (error) {
logger.error('Error running check:', error.message)
logger.error(error)
process.exit(1)
} finally {
await knex.destroy()
Expand All @@ -77,7 +77,7 @@ check
try {
await runCheckCommand(knex, options)
} catch (error) {
logger.error('Error running check:', error.message)
logger.error(error)
process.exit(1)
} finally {
await knex.destroy()
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"knex": "3.1.0",
"octokit": "3.2.1",
"pg": "8.13.1",
"pino": "^9.5.0",
"pino-pretty": "^13.0.0",
"validator": "13.12.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/workflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const commandList = [{
const validCommandNames = commandList.map(({ name }) => name)

function listWorkflowCommand (options = {}) {
logger.log('Available workflows:')
logger.log(commandList.map(({ name, description }) => `- ${name}: ${description}`).join('\n'))
logger.log('Available workflows: \n')
commandList.forEach(({ name, description }) => logger.log(`- ${name}: ${description}`))
return commandList
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const performScorecardAnalysis = async (repo) => {
const start = new Date().getTime()
const { stdout, stderr } = await exec(`docker run -e GITHUB_AUTH_TOKEN=${process.env.GITHUB_TOKEN} --rm ${ossfScorecardSettings.dockerImage} --repo=${repo.html_url} --show-details --format=json`)
if (stderr) {
console.error(stderr)
logger.error(stderr)
throw new Error(`Error running OSSF Scorecard for repository (${repo.full_name})`)
}
const data = JSON.parse(stdout)
Expand Down
11 changes: 9 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const { add, parseISO, isBefore } = require('date-fns')
const isURL = require('validator/lib/isURL.js')
const pino = require('pino')({
transport: {
target: 'pino-pretty'
},
level: process.env.PINO_LOG_LEVEL || 'trace'
})

const validateGithubUrl = (url) => isURL(url, { protocols: ['https'], require_protocol: true }) && url.includes('github.com')

Expand All @@ -13,14 +19,15 @@ const defineLog = (type) => function () {
if (process.env.NODE_ENV === 'test') {
return () => {}
}
return console[type](...arguments)

return pino[type](...arguments)
}

const logger = {
info: defineLog('info'),
error: defineLog('error'),
warn: defineLog('warn'),
log: defineLog('log')
log: defineLog('trace')
}

const getSeverityFromPriorityGroup = (priorityGroup) => {
Expand Down

0 comments on commit 7c73879

Please sign in to comment.