logging.js 892 B

1234567891011121314151617181920212223242526272829
  1. import { createWriteStream } from 'fs';
  2. /**
  3. * Log wikis by usage.
  4. * @param {import('./wiki.js').default} wiki - The wiki.
  5. * @param {String} [guild] - The guild.
  6. * @param {String[]} [notes] - The notes about the usage.
  7. */
  8. var logging = function(wiki, guild, ...notes) {};
  9. if ( process.env.usagelog ) {
  10. const usageLog = createWriteStream(process.env.usagelog, {flags:'a'});
  11. usageLog.on( 'error', (error) => {
  12. console.log( '- ' + process.env.SHARDS + ': Error while logging the usage: ' + error );
  13. } );
  14. /**
  15. * Log wikis by usage.
  16. * @param {import('./wiki.js').default} wiki - The wiki.
  17. * @param {String} [guild] - The guild.
  18. * @param {String[]} [notes] - The notes about the usage.
  19. */
  20. logging = function(wiki, guild, ...notes) {
  21. usageLog.write( [new Date().toISOString(), wiki, ( guild || 'DM' ), ...notes].join('\t') + '\n', 'utf8' );
  22. };
  23. }
  24. export default logging;