padLevels.js 903 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const { format } = require('../');
  2. const { combine, padLevels, simple } = format;
  3. const { MESSAGE } = require('triple-beam');
  4. const paddedFormat = combine(
  5. padLevels({
  6. // Uncomment for a custom filler for the padding, defaults to ' '.
  7. // filler: 'foo',
  8. // Levels has to be defined, same as `winston.createLoggers({ levels })`.
  9. levels: {
  10. error: 0,
  11. warn: 1,
  12. info: 2,
  13. http: 3,
  14. verbose: 4,
  15. debug: 5,
  16. silly: 6
  17. }
  18. }),
  19. simple()
  20. );
  21. const info = paddedFormat.transform({
  22. level: 'info',
  23. message: 'This is an info level message.'
  24. });
  25. const error = paddedFormat.transform({
  26. level: 'error',
  27. message: 'This is an error level message.'
  28. });
  29. const verbose = paddedFormat.transform({
  30. level: 'verbose',
  31. message: 'This is a verbose level message.'
  32. });
  33. console.dir(info[MESSAGE]);
  34. console.dir(error[MESSAGE]);
  35. console.dir(verbose[MESSAGE]);