logging.js 619 B

1234567891011121314151617181920212223
  1. if ( !process.env.usagelog ) {
  2. module.exports = function() {};
  3. return;
  4. }
  5. const fs = require('fs');
  6. const usageLog = fs.createWriteStream(process.env.usagelog, {flags:'a'});
  7. usageLog.on( 'error', (error) => {
  8. console.log( '- ' + shardId + ': Error while logging the usage: ' + error );
  9. } );
  10. /**
  11. * Log wikis by usage.
  12. * @param {import('./wiki.js')} wiki - The wiki.
  13. * @param {String[]} notes - The notes about the usage.
  14. * @returns {Boolean}
  15. */
  16. function logging(wiki, ...notes) {
  17. return usageLog.write( `${new Date().toISOString()}\t${wiki.href}\t${notes.join('\t')}\n`, 'utf8' );
  18. }
  19. module.exports = logging;