log.ts 1.1 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 dispEpisode(name: string, status: string, addNL: boolean)
  25. {
  26. /* Do fancy output */
  27. process.stdout.write('\x1B[K \x1B[1;33m> \x1B[37m' + name + '\x1B[0m : \x1B[33m' + status + '\x1B[0m\x1B[0G');
  28. if (addNL)
  29. {
  30. console.log('');
  31. }
  32. }
  33. export function dumpToDebug(what: string, data: any, create = false)
  34. {
  35. if (create)
  36. {
  37. fs.writeFile('debug.txt', '>>>>>>>> ' + what + ':\n' + data + '\n<<<<<<<<\n', (err) =>
  38. {
  39. if (err) throw err;
  40. });
  41. return;
  42. }
  43. fs.appendFile('debug.txt', '>>>>>>>> ' + what + ':\n' + data + '\n<<<<<<<<\n', (err) =>
  44. {
  45. if (err) throw err;
  46. });
  47. }