UNPKG

3.71 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright © 2020 Atomist, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18const skill_logging_1 = require("@atomist/skill-logging");
19const redact_1 = require("./redact");
20const util_1 = require("./util");
21function 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}
43exports.wrapAuditLogger = wrapAuditLogger;
44/**
45 * Print the debug level message to stdout
46 *
47 * @param message The message to print
48 * @param optionalParams Optional params to pass to the logger
49 */
50function debug(message, ...optionalParams) {
51 if (enabled("debug")) {
52 // tslint:disable-next-line:no-console
53 console.debug(`[debug] ${redact_1.redact(message)}`, ...optionalParams);
54 }
55}
56exports.debug = debug;
57/**
58 * Print the info level message to stdout
59 *
60 * @param message The message to print
61 * @param optionalParams Optional params to pass to the logger
62 */
63function info(message, ...optionalParams) {
64 if (enabled("info")) {
65 // tslint:disable-next-line:no-console
66 console.info(` [info] ${redact_1.redact(message)}`, ...optionalParams);
67 }
68}
69exports.info = info;
70/**
71 * Print the warn level message to stdout
72 *
73 * @param message The message to print
74 * @param optionalParams Optional params to pass to the logger
75 */
76function warn(message, ...optionalParams) {
77 if (enabled("warn")) {
78 // tslint:disable-next-line:no-console
79 console.warn(` [warn] ${redact_1.redact(message)}`, ...optionalParams);
80 }
81}
82exports.warn = warn;
83/**
84 * Print the error level message to stdout
85 *
86 * @param message The message to print
87 * @param optionalParams Optional params to pass to the logger
88 */
89function error(message, ...optionalParams) {
90 if (enabled("error")) {
91 // tslint:disable-next-line:no-console
92 console.error(`[error] ${redact_1.redact(message)}`, ...optionalParams);
93 }
94}
95exports.error = error;
96var 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 = {}));
103function enabled(level) {
104 const configuredLevel = Level[process.env.ATOMIST_LOG_LEVEL || "debug"];
105 return configuredLevel >= Level[level];
106}
107//# sourceMappingURL=log.js.map
\No newline at end of file