UNPKG

2.54 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright © 2018 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 automation_client_1 = require("@atomist/automation-client");
19const EphemeralProgressLog_1 = require("@atomist/sdm/api-helper/log/EphemeralProgressLog");
20const firstAvailableProgressLog_1 = require("@atomist/sdm/api-helper/log/firstAvailableProgressLog");
21const LoggingProgressLog_1 = require("@atomist/sdm/api-helper/log/LoggingProgressLog");
22const WriteToAllProgressLog_1 = require("@atomist/sdm/api-helper/log/WriteToAllProgressLog");
23const DashboardDisplayProgressLog_1 = require("./DashboardDisplayProgressLog");
24/**
25 * Create a progress log that will use Rolar logging service if available,
26 * otherwise falling back to logging.
27 * @param {string} rolarBaseUrl
28 * @param {string} dashboardBaseUrl
29 * @return {ProgressLogFactory}
30 */
31function rolarAndDashboardLogFactory(rolarBaseUrl, bufferSize = 1000, flushInterval = 2000) {
32 let persistentLogFactory = (context, sdmGoal, fallback) => firstAvailableProgressLog_1.firstAvailableProgressLog(fallback);
33 if (rolarBaseUrl) {
34 automation_client_1.logger.info("Logging with Rolar: " + rolarBaseUrl);
35 persistentLogFactory = (context, sdmGoal, fallback) => {
36 return firstAvailableProgressLog_1.firstAvailableProgressLog(new DashboardDisplayProgressLog_1.DashboardDisplayProgressLog(rolarBaseUrl, bufferSize, flushInterval, context, sdmGoal), fallback);
37 };
38 }
39 return async (context, sdmGoal) => {
40 const name = sdmGoal.name;
41 const persistentLog = await persistentLogFactory(context, sdmGoal, new LoggingProgressLog_1.LoggingProgressLog(name, "info"));
42 return new WriteToAllProgressLog_1.WriteToAllProgressLog(name, await EphemeralProgressLog_1.createEphemeralProgressLog(context, sdmGoal), persistentLog);
43 };
44}
45exports.rolarAndDashboardLogFactory = rolarAndDashboardLogFactory;
46//# sourceMappingURL=rolarAndDashboardLogFactory.js.map
\No newline at end of file