"use strict";
/*
 * Copyright © 2020 Atomist, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.createEphemeralProgressLog = void 0;
const logger_1 = require("@atomist/automation-client/lib/util/logger");
const format_1 = require("./format");
/**
 * Implementation of ProgressLog log that returns
 * an undefined link because it isn't actually persisted.
 * Used when we are not storing a local log.
 * Writes to logger at info level.
 */
class EphemeralProgressLog {
    constructor(name, writeToLog = true) {
        this.name = name;
        this.writeToLog = writeToLog;
        this.log = "";
        this.url = undefined;
    }
    async isAvailable() { return true; }
    flush() {
        return Promise.resolve();
    }
    async close() {
        if (this.writeToLog) {
            logger_1.logger.info(`Progress log '${this.name}'\n${this.log.trim()}`);
        }
    }
    write(what, ...args) {
        if (!what && what !== "") {
            return;
        }
        let line = format_1.format(what, ...args);
        if (!line.endsWith("\n")) {
            line += "\n";
        }
        this.log += line;
    }
}
const createEphemeralProgressLog = async (context, sdmGoal) => new EphemeralProgressLog(sdmGoal.uniqueName);
exports.createEphemeralProgressLog = createEphemeralProgressLog;
//# sourceMappingURL=EphemeralProgressLog.js.map