Skip to content

Commit

Permalink
Merge refs/heads/master into version_4.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Jan 18, 2022
2 parents eecd7f3 + fdf14ca commit 93f7872
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 3 additions & 1 deletion server/utils/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const logger = winston.createLogger({
format: format.combine(
format.splat(),
format.padLevels(),
format.timestamp(),
format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss.SSSZZ'
}),
format.printf(info => `${info.timestamp} [${info.level.toUpperCase()}] ${info.message}`)
)
})
Expand Down
21 changes: 21 additions & 0 deletions test/logging.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const chai = require('chai')
const assert = chai.assert
const path = require('path')
const fs = require('fs').promises
const logger = require('../server/utils/logging.js')

const convertOneDigitToTwo = (number) => {
return ('0' + (number)).slice(-2)
}

describe('logging', () => {
it('should log currect datetime', async () => {
logger.log2('debug', 'hello this is a dummy log testing')
const passportLogFilePath = path.join(__dirname, '../server/utils/logs/passport.log')
const logText = await fs.readFile(passportLogFilePath, 'binary')
const newDate = new Date()
// YYYY-MM-DD HH
const currentDateTimeTillHour = `${newDate.getFullYear()}-${convertOneDigitToTwo(newDate.getMonth() + 1)}-${convertOneDigitToTwo(newDate.getDate())} ${convertOneDigitToTwo(newDate.getHours())}`
assert(logText.includes(currentDateTimeTillHour), 'hello this is a dummy log testing')
})
})
7 changes: 0 additions & 7 deletions test/logging.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ describe('logging.js file', () => {
it('write property should be function', () => {
assert.isFunction(rewiredLogger.stream.write, 'steam.write is not a function')
})
it('write property should call log2 once', () => {
// Todo this case is failing
// const rewiredLog2 = rewiredLogging.__get__('log2')
// const log2Spy = sinon.spy(rewiredLog2)
// rewiredLogger.stream.write('tEMp')
// sinon.assert.calledOnce(log2Spy)
})
})
})
})

0 comments on commit 93f7872

Please sign in to comment.