cocalc/src / smc-project / node_modules / broadway / node_modules / winston / test / custom-timestamp-test.js
50659 views/*1* custom-timestamp-test.js: Test function as timestamp option for transport `{ timestamp: function () {} }`2*3* (C) 2011 Charlie Robbins, Tom Shinnick4* MIT LICENSE5*6*/78var assert = require('assert'),9events = require('events'),10fs = require('fs'),11path = require('path'),12vows = require('vows'),13winston = require('../lib/winston'),14helpers = require('./helpers');1516function assertTimestamp (basename, options) {17var filename = path.join(__dirname, 'fixtures', 'logs', basename + '.log');1819try { fs.unlinkSync(filename) }20catch (ex) { }2122return {23topic: function () {24options.filename = filename;25var transport = new (winston.transports.File)(options);2627// We must wait until transport file has emitted the 'flush'28// event to be sure the file has been created and written29transport.once('flush', this.callback.bind(this, null, filename));30transport.log('info', 'When a fake tree falls in the forest...', null, function () {});31},32"should log with the appropriate timestamp": function (_, filename) {33var data = fs.readFileSync(filename, 'utf8');34assert.isNotNull(data.match(options.pattern));35}36}37}3839vows.describe('winston/transport/timestamp').addBatch({40"When timestamp option is used": {41"with file transport": {42"with value set to false": assertTimestamp('noTimestamp', {43pattern: /^info\:/,44json: false,45timestamp: false46}),47"with value set to true ": assertTimestamp('defaultTimestamp', {48pattern: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/,49json: false,50timestamp: true51}),52"and function value": assertTimestamp('customTimestamp', {53pattern: /^\d{8}\./,54json: false,55timestamp: function () {56return '20110803.171657';57}58})59}60}61}).export(module);6263