message.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. var __assign = (this && this.__assign) || function () {
  3. __assign = Object.assign || function(t) {
  4. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5. s = arguments[i];
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  7. t[p] = s[p];
  8. }
  9. return t;
  10. };
  11. return __assign.apply(this, arguments);
  12. };
  13. var __importDefault = (this && this.__importDefault) || function (mod) {
  14. return (mod && mod.__esModule) ? mod : { "default": mod };
  15. };
  16. Object.defineProperty(exports, "__esModule", { value: true });
  17. var fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
  18. var context_1 = require("./context");
  19. var level_1 = require("./level");
  20. var LogFormatters = defaultLogFormatters();
  21. exports.LogFormatters = LogFormatters;
  22. var resetLogFormatters = function () {
  23. exports.LogFormatters = LogFormatters = defaultLogFormatters();
  24. };
  25. exports.resetLogFormatters = resetLogFormatters;
  26. var registerLogFormatter = function (name, format) {
  27. LogFormatters[name] = format;
  28. };
  29. exports.registerLogFormatter = registerLogFormatter;
  30. function defaultLogFormatters() {
  31. return {
  32. json: function (msg) { return fast_json_stable_stringify_1.default(__assign({}, msg, { time: new Date(msg.time) }), { cycles: true }); },
  33. simple: function (msg) {
  34. return (msg.context[context_1.LogContexts.package] || msg.context[context_1.LogContexts.application] || 'main') + "[" + (msg.context[context_1.LogContexts.namespace] || 'root') + "] (" + level_1.logLevelNameFor(msg.context[context_1.LogContexts.logLevel]).toUpperCase() + ") " + msg.message;
  35. },
  36. };
  37. }