log.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. import os = require('os');
  3. import fs = require('fs-extra');
  4. export function error(str: string|Error)
  5. {
  6. /* Do fancy output */
  7. console.error(' \x1B[1;31m* ERROR\x1B[0m: ' + str);
  8. }
  9. export function info(str: string)
  10. {
  11. /* Do fancy output */
  12. console.log(' \x1B[1;32m* INFO \x1B[0m: ' + str);
  13. }
  14. export function debug(str: string)
  15. {
  16. /* Do fancy output */
  17. console.log(' \x1B[1;35m* DEBUG\x1B[0m: ' + str);
  18. }
  19. export function warn(str: string)
  20. {
  21. /* Do fancy output */
  22. console.log(' \x1B[1;33m* WARN \x1B[0m: ' + str);
  23. }
  24. export function warnMore(str: string)
  25. {
  26. /* Do fancy output */
  27. console.log(' \x1B[1;38;5;166m* WARN \x1B[0m: ' + str);
  28. }
  29. export function dispEpisode(name: string, status: string, addNL: boolean)
  30. {
  31. /* Do fancy output */
  32. process.stdout.write('\x1B[K \x1B[1;33m> \x1B[37m' + name + '\x1B[0m : \x1B[33m' + status + '\x1B[0m\x1B[0G');
  33. if (addNL)
  34. {
  35. console.log('');
  36. }
  37. }
  38. export function dumpToDebug(what: string, data: any, create = false)
  39. {
  40. if (create)
  41. {
  42. fs.writeFileSync('debug.txt', '>>>>>>>> ' + what + ':\n' + data + '\n<<<<<<<<\n');
  43. return;
  44. }
  45. fs.appendFileSync('debug.txt', '>>>>>>>> ' + what + ':\n' + data + '\n<<<<<<<<\n');
  46. }