logging.js 652 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} [guild] - The guild.
  14. * @param {String[]} [notes] - The notes about the usage.
  15. */
  16. function logging(wiki, guild = 'DM', ...notes) {
  17. usageLog.write( [new Date().toISOString(), wiki.href, guild, ...notes].join('\t') + '\n', 'utf8' );
  18. }
  19. module.exports = logging;