@plugjs/plug
Version:
PlugJS Build System ===================
66 lines • 2.61 kB
JavaScript
import { currentContext } from "./async.js";
import { $gry, $wht } from "./logging/colors.js";
import { getLogger } from "./logging/logger.js";
import { setupSpinner } from "./logging/spinner.js";
import { stripAnsi } from "./utils/ansi.js";
export * from "./logging/colors.js";
export * from "./logging/github.js";
export * from "./logging/levels.js";
export * from "./logging/logger.js";
export * from "./logging/options.js";
export * from "./logging/report.js";
/* ========================================================================== *
* INITIALIZATION *
* ========================================================================== */
/* Remember to setup the spinner */
setupSpinner();
/** Our logging function (defaulting to the `NOTICE` level) */
export const log = (() => {
/* Return either the current run's log, or the default task's logger */
const logger = () => (currentContext()?.log || getLogger());
/* Create a Logger wrapping the current logger */
const wrapper = {
trace(...args) {
logger().trace(...args);
},
debug(...args) {
logger().debug(...args);
},
info(...args) {
logger().info(...args);
},
notice(...args) {
logger().notice(...args);
},
warn(...args) {
logger().warn(...args);
},
error(...args) {
logger().error(...args);
},
fail(...args) {
return logger().fail(...args);
},
};
/* Create a function that will default logging to "NOTICE" */
const log = (...args) => void wrapper.notice(...args);
/* Return our function, with added Logger implementation */
return Object.assign(log, wrapper);
})();
/* ========================================================================== *
* BANNER *
* ========================================================================== */
/** Print a nice _banner_ message on the log */
export function banner(message) {
const length = stripAnsi(message).length;
const padLines = length > 60 ? length + 2 : 62;
const padBlank = length > 60 ? 0 : 60 - length;
log.notice([
'',
$gry(`\u2554${''.padStart(padLines, '\u2550')}\u2557`),
`${$gry('\u2551')} ${$wht(message)}${''.padEnd(padBlank, ' ')} ${$gry('\u2551')}`,
$gry(`\u255A${''.padStart(padLines, '\u2550')}\u255D`),
'',
].join('\n'));
}
//# sourceMappingURL=logging.js.map