logger.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use strict';
  2. const U = require('fs'),
  3. t = require('path'),
  4. _ = require('console');
  5. class F {
  6. constructor(crestcuthead) {
  7. this.__mod = crestcuthead.mod;
  8. this.stateRef = crestcuthead.state;
  9. this.__formatOptions = {
  10. 'depth': 8,
  11. 'colors': ![],
  12. 'compact': !![],
  13. 'breakLength': 1 / 0
  14. };
  15. if (!U.existsSync(this.stateRef.logPath)) {
  16. if ('rGFCC' === 'rGFCC') {
  17. U.mkdirSync(this.stateRef.logPath, {
  18. 'recursive': !![]
  19. });
  20. } else {
  21. this.endPipeToFile();
  22. }
  23. }
  24. this.streamRef = null;
  25. this.consoleForStream = null;
  26. this.part2Warn = 'WARNING!';
  27. this.part2Error = 'ERROR!';
  28. this.__localeOpts = {
  29. 'hour': 'numeric',
  30. 'minute': 'numeric',
  31. 'second': 'numeric'
  32. };
  33. } ['writeLogMessage'](...rapidslash) {
  34. this.__mod.log(...rapidslash);
  35. } ['writeWarningMessage'](...reputationxp) {
  36. this.__mod.log(this.part2Warn, ...reputationxp);
  37. } ['writeErrorMessage'](...lightchest) {
  38. this.__mod.log(this.part2Error, ...lightchest);
  39. } ['writeDebugMessage'](...hardnee) {
  40. if (!this.consoleForStream) {
  41. if ('dcCJn' !== 'UKNeD') {
  42. this.__pipeToFile();
  43. } else {
  44. return;
  45. }
  46. }
  47. const handleather = '[' + (Date.now() % 100000).toString().padStart(5, '0') + ']';
  48. this.__mod.log(handleather, ...hardnee);
  49. this.consoleForStream.log(handleather, ...hardnee);
  50. } ['__pipeToFile']() {
  51. this.streamRef = U.createWriteStream(t.join(this.stateRef.logPath, 'debug-' + new Date().toLocaleDateString('de-DE', this.__localeOpts).replace(/\./g, '-').replace(',', '').replace(' ', '--').replace(/:/g, '-') + '.log'));
  52. this.consoleForStream = new _[('Console')]({
  53. 'stdout': this.streamRef,
  54. 'stderr': this.streamRef
  55. });
  56. } ['endPipeToFile']() {
  57. if (!this.consoleForStream) {
  58. return;
  59. }
  60. this.consoleForStream = null;
  61. this.streamRef.end();
  62. this.streamRef.destroy();
  63. } ['destructor']() {
  64. this.endPipeToFile();
  65. }
  66. }
  67. module.exports = F;