1 | var _a;
|
2 | import { __assign, __decorate } from "tslib";
|
3 | import { combine, createContextManager, ErrorOrigin, monitored } from '@datadog/browser-core';
|
4 | export var StatusType;
|
5 | (function (StatusType) {
|
6 | StatusType["debug"] = "debug";
|
7 | StatusType["info"] = "info";
|
8 | StatusType["warn"] = "warn";
|
9 | StatusType["error"] = "error";
|
10 | })(StatusType || (StatusType = {}));
|
11 | export var STATUS_PRIORITIES = (_a = {},
|
12 | _a[StatusType.debug] = 0,
|
13 | _a[StatusType.info] = 1,
|
14 | _a[StatusType.warn] = 2,
|
15 | _a[StatusType.error] = 3,
|
16 | _a);
|
17 | export var STATUSES = Object.keys(StatusType);
|
18 | export var HandlerType;
|
19 | (function (HandlerType) {
|
20 | HandlerType["http"] = "http";
|
21 | HandlerType["console"] = "console";
|
22 | HandlerType["silent"] = "silent";
|
23 | })(HandlerType || (HandlerType = {}));
|
24 | var Logger = (function () {
|
25 | function Logger(sendLog, handlerType, level, loggerContext) {
|
26 | if (handlerType === void 0) { handlerType = HandlerType.http; }
|
27 | if (level === void 0) { level = StatusType.debug; }
|
28 | if (loggerContext === void 0) { loggerContext = {}; }
|
29 | this.sendLog = sendLog;
|
30 | this.handlerType = handlerType;
|
31 | this.level = level;
|
32 | this.contextManager = createContextManager();
|
33 | this.contextManager.set(loggerContext);
|
34 | }
|
35 | Logger.prototype.log = function (message, messageContext, status) {
|
36 | if (status === void 0) { status = StatusType.info; }
|
37 | if (STATUS_PRIORITIES[status] >= STATUS_PRIORITIES[this.level]) {
|
38 | switch (this.handlerType) {
|
39 | case HandlerType.http:
|
40 | this.sendLog(__assign({ message: message,
|
41 | status: status }, combine(this.contextManager.get(), messageContext)));
|
42 | break;
|
43 | case HandlerType.console:
|
44 | console.log(status + ": " + message);
|
45 | break;
|
46 | case HandlerType.silent:
|
47 | break;
|
48 | }
|
49 | }
|
50 | };
|
51 | Logger.prototype.debug = function (message, messageContext) {
|
52 | this.log(message, messageContext, StatusType.debug);
|
53 | };
|
54 | Logger.prototype.info = function (message, messageContext) {
|
55 | this.log(message, messageContext, StatusType.info);
|
56 | };
|
57 | Logger.prototype.warn = function (message, messageContext) {
|
58 | this.log(message, messageContext, StatusType.warn);
|
59 | };
|
60 | Logger.prototype.error = function (message, messageContext) {
|
61 | var errorOrigin = {
|
62 | error: {
|
63 | origin: ErrorOrigin.LOGGER,
|
64 | },
|
65 | };
|
66 | this.log(message, combine(errorOrigin, messageContext), StatusType.error);
|
67 | };
|
68 | Logger.prototype.setContext = function (context) {
|
69 | this.contextManager.set(context);
|
70 | };
|
71 | Logger.prototype.addContext = function (key, value) {
|
72 | this.contextManager.add(key, value);
|
73 | };
|
74 | Logger.prototype.removeContext = function (key) {
|
75 | this.contextManager.remove(key);
|
76 | };
|
77 | Logger.prototype.setHandler = function (handler) {
|
78 | this.handlerType = handler;
|
79 | };
|
80 | Logger.prototype.setLevel = function (level) {
|
81 | this.level = level;
|
82 | };
|
83 | __decorate([
|
84 | monitored
|
85 | ], Logger.prototype, "log", null);
|
86 | return Logger;
|
87 | }());
|
88 | export { Logger };
|
89 |
|
\ | No newline at end of file |