Guest User

Untitled

a guest
Oct 24th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. var dateFormat = require('dateformat');
  2. var colors = require('colors');
  3. var winston = require('winston');
  4. winston.add(winston.transports.File, { filename: '/var/log/nomp/nomp.log', maxsize: 262144000, maxFiles: 25 });
  5. winston.remove(winston.transports.Console);
  6.  
  7. var severityToColor = function(severity, text) {
  8. switch(severity) {
  9. case 'special':
  10. return text.cyan.underline;
  11. case 'debug':
  12. return text.green;
  13. case 'warning':
  14. return text.yellow;
  15. case 'error':
  16. return text.red;
  17. default:
  18. console.log("Unknown severity " + severity);
  19. return text.italic;
  20. }
  21. };
  22.  
  23. var severityValues = {
  24. 'debug': 1,
  25. 'warning': 2,
  26. 'error': 3,
  27. 'special': 4
  28. };
  29.  
  30.  
  31. var PoolLogger = function (configuration) {
  32.  
  33.  
  34. var logLevelInt = severityValues[configuration.logLevel];
  35.  
  36.  
  37.  
  38. var log = function(severity, system, component, text, subcat) {
  39.  
  40. if (severityValues[severity] < logLevelInt) return;
  41.  
  42. if (subcat){
  43. var realText = subcat;
  44. var realSubCat = text;
  45. text = realText;
  46. subcat = realSubCat;
  47. }
  48.  
  49. var entryDesc = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss') + ' [' + system + ']\t';
  50. var logString =
  51. entryDesc +
  52. ('[' + component + '] ');
  53.  
  54. if (subcat)
  55. logString += ('(' + subcat + ') ')
  56.  
  57. winston.info( ' [' + system + '] ' + ('[' + component + '] ') + ('(' + subcat + ') ') + text);
  58.  
  59.  
  60. };
  61.  
  62. // public
  63.  
  64. var _this = this;
  65. Object.keys(severityValues).forEach(function(logType){
  66. _this[logType] = function(){
  67. var args = Array.prototype.slice.call(arguments, 0);
  68. args.unshift(logType);
  69. log.apply(this, args);
  70. };
  71. });
  72. };
  73.  
  74. module.exports = PoolLogger;
Add Comment
Please, Sign In to add comment