diff --git a/server/utils/logging.js b/server/utils/logging.js index 68006cc8..7cc79410 100644 --- a/server/utils/logging.js +++ b/server/utils/logging.js @@ -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}`) ) }) diff --git a/test/logging.spec.js b/test/logging.spec.js new file mode 100644 index 00000000..42c8b3ed --- /dev/null +++ b/test/logging.spec.js @@ -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') + }) +}) diff --git a/test/logging.test.js b/test/logging.test.js index bfce568b..d66ec308 100644 --- a/test/logging.test.js +++ b/test/logging.test.js @@ -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) - }) }) }) })