1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const skill_logging_1 = require("@atomist/skill-logging");
|
19 | const redact_1 = require("./redact");
|
20 | const util_1 = require("./util");
|
21 | function wrapAuditLogger(context, labels = {}) {
|
22 | const logger = skill_logging_1.createLogger(context, labels);
|
23 | return {
|
24 | log: async (msg, severity = skill_logging_1.Severity.INFO, labels) => {
|
25 | const msgs = util_1.toArray(msg);
|
26 | switch (severity) {
|
27 | case skill_logging_1.Severity.WARNING:
|
28 | msgs.forEach(m => warn(m));
|
29 | break;
|
30 | case skill_logging_1.Severity.ERROR:
|
31 | msgs.forEach(m => error(m));
|
32 | break;
|
33 | default:
|
34 | msgs.forEach(m => info(m));
|
35 | break;
|
36 | }
|
37 | return logger.log(msg, severity, labels);
|
38 | },
|
39 | url: `https://go.atomist.${(process.env.ATOMIST_GRAPHQL_ENDPOINT || "").includes("staging")
|
40 | ? "services" : "com"}/log/${context.workspaceId}/${context.correlationId}`,
|
41 | };
|
42 | }
|
43 | exports.wrapAuditLogger = wrapAuditLogger;
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | function debug(message, ...optionalParams) {
|
51 | if (enabled("debug")) {
|
52 |
|
53 | console.debug(`[debug] ${redact_1.redact(message)}`, ...optionalParams);
|
54 | }
|
55 | }
|
56 | exports.debug = debug;
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | function info(message, ...optionalParams) {
|
64 | if (enabled("info")) {
|
65 |
|
66 | console.info(` [info] ${redact_1.redact(message)}`, ...optionalParams);
|
67 | }
|
68 | }
|
69 | exports.info = info;
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | function warn(message, ...optionalParams) {
|
77 | if (enabled("warn")) {
|
78 |
|
79 | console.warn(` [warn] ${redact_1.redact(message)}`, ...optionalParams);
|
80 | }
|
81 | }
|
82 | exports.warn = warn;
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | function error(message, ...optionalParams) {
|
90 | if (enabled("error")) {
|
91 |
|
92 | console.error(`[error] ${redact_1.redact(message)}`, ...optionalParams);
|
93 | }
|
94 | }
|
95 | exports.error = error;
|
96 | var Level;
|
97 | (function (Level) {
|
98 | Level[Level["error"] = 0] = "error";
|
99 | Level[Level["warn"] = 1] = "warn";
|
100 | Level[Level["info"] = 2] = "info";
|
101 | Level[Level["debug"] = 3] = "debug";
|
102 | })(Level || (Level = {}));
|
103 | function enabled(level) {
|
104 | const configuredLevel = Level[process.env.ATOMIST_LOG_LEVEL || "debug"];
|
105 | return configuredLevel >= Level[level];
|
106 | }
|
107 |
|
\ | No newline at end of file |