Skip to content

Commit

Permalink
Use vite's built in logger instead of console methods
Browse files Browse the repository at this point in the history
  • Loading branch information
LorisSigrist committed Oct 4, 2023
1 parent b6995a3 commit f98eeac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function t18s(userConfig = {}) {
verbose: fullUserConfig.verbose,
};

logger = new Logger(config.verbose);
logger = new Logger(resolvedConfig, config.verbose);
adapter = new SvelteStoreAdapter(config);

await loadInitialLocales(config);
Expand Down
18 changes: 13 additions & 5 deletions src/core/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ import colors from "kleur";
*/
export class Logger {
#verbose = false;
/** @type {import("vite").ResolvedConfig} */
#viteConfig;

constructor(verbose = false) {
/**
*
* @param {import("vite").ResolvedConfig} viteConfig
* @param {boolean} verbose
*/
constructor(viteConfig, verbose = false) {
this.#viteConfig = viteConfig;
this.#verbose = verbose;
}

Expand All @@ -19,7 +27,7 @@ export class Logger {
log(msg) {
if (!this.#verbose) return;
msg = this.#formatMessage(msg, "ⓘ");
console.log(colors.cyan(msg));
this.#viteConfig.logger.info(colors.cyan(msg));
}

/**
Expand All @@ -30,7 +38,7 @@ export class Logger {
warn(msg) {
if (!this.#verbose) return;
msg = this.#formatMessage(msg);
console.warn(colors.bold().yellow(msg));
this.#viteConfig.logger.warn(colors.bold().yellow(msg));
}

/**
Expand All @@ -39,7 +47,7 @@ export class Logger {
*/
error(msg) {
msg = this.#formatMessage(msg, "✗");
console.error(colors.bold().red(msg));
this.#viteConfig.logger.error(colors.bold().red(msg));
}

/**
Expand All @@ -48,7 +56,7 @@ export class Logger {
*/
success(msg) {
msg = this.#formatMessage(msg, "✔");
console.log(colors.green(msg));
this.#viteConfig.logger.info(colors.green(msg));
}

/**
Expand Down

0 comments on commit f98eeac

Please sign in to comment.