SIGN IN SIGN UP

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.

0 0 1 Java
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import wrap from "fast-word-wrap";
export class Logger {
constructor(lineLength = 80) {
this.lineLength = lineLength;
}
/**
* @param {string} message
*/
log(message) {
console.log(message);
return Promise.resolve();
}
/**
* @param {{ oneLineOnly: boolean }} options
*/
hr({ oneLineOnly } = { oneLineOnly: false }) {
const rule = "*".repeat(this.lineLength);
return oneLineOnly ? rule : ["\n", rule, "\n"].join("");
}
/**
* @param {string} message
*/
box(message) {
const linePrefix = "* ";
const lineSuffix = " *";
const maxContentLength = this.lineLength - (linePrefix + lineSuffix).length;
const chunks = message
.split("\n")
.flatMap((l) => l && wrap(l, maxContentLength).split("\n"));
/**
* @param {string} c
*/
const fill = (c) => c + " ".repeat(maxContentLength - c.length);
/**
* @param {string} c
*/
const line = (c) => `${linePrefix}${fill(c)}${lineSuffix}`;
return [this.hr(), chunks.map(line).join("\n"), this.hr()].join("");
}
/**
* Log a horizontal rule to the console. If a message is provided,
* log a section header.
* @param {string?} message
*/
logSeparator(message) {
if (!message) {
console.log(this.hr());
} else {
console.log(this.box(message));
}
}
}