Skip to content

Commit

Permalink
refactor: tweak up logger config
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed May 25, 2023
1 parent 3fb6584 commit 76f5948
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Alternatively some options may be set via CLI flags.
| dryRun | `boolean` | `--dry-run` | Dry run mode. |
| logLevel | `String` | `--log-level` | Sets the internal logger verbosity level: `error, warn, info, debug, trace`. Defaults to `info`. |
| debug | `boolean` | `--debug` | Output debugging information. Shortcut for `--logLevel=debug`. |
| silent | `boolean` | `--silent` | Do not print configuration information. Shortcut for `--logLevel=error`. |
| silent | `boolean` | `--silent` | Turns off any log outputs. |
| extends | `String \| Array` | N/A | List of modules or file paths containing a shareable configuration. If multiple shareable configurations are set, they will be imported in the order defined with each configuration option taking precedence over the options defined in the previous. |
| sequentialInit | `boolean` | `--sequential-init` | Avoid hypothetical concurrent initialization collisions. |
| sequentialPrepare | `boolean` | `--sequential-prepare` | Avoid hypothetical concurrent preparation collisions. **True by default.** |
Expand Down
5 changes: 3 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import meow from "meow";
import process from "process";
import { toPairs, set } from "lodash-es";
import { logger } from "../lib/logger.js";

const cli = meow(
`
Expand Down Expand Up @@ -107,13 +108,13 @@ const runner = async (cliFlags) => {
},
(error) => {
// Log out errors.
console.error(`[multi-semantic-release]:`, error);
logger.error(`[multi-semantic-release]:`, error);
process.exit(1);
}
);
} catch (error) {
// Log out errors.
console.error(`[multi-semantic-release]:`, error);
logger.error(`[multi-semantic-release]:`, error);
process.exit(1);
}
};
Expand Down
3 changes: 3 additions & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const logger = {
_stdout: process.stdout,
_signale: {},
set level(l) {
if (!l) {
return;
}
if (assertLevel(l, "debug")) {
dbg.enable("msr:");
}
Expand Down
22 changes: 11 additions & 11 deletions lib/multiSemanticRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ async function multiSemanticRelease(
{ cwd = process.cwd(), env = process.env, stdout = process.stdout, stderr = process.stderr } = {},
_flags
) {
// Setup logger.
logger.config.stdio = [stderr, stdout];

// Check params.
if (paths) {
check(paths, "paths: string[]");
Expand All @@ -66,20 +63,24 @@ async function multiSemanticRelease(
cwd = cleanPath(cwd);

const flags = normalizeFlags(await getConfigMultiSemrel(cwd, _flags));
const silent = flags.silent && !flags.debug;
const require = createRequire(import.meta.url);
const multisemrelPkgJson = require("../package.json");
const semrelPkgJson = require("semantic-release/package.json");

if (!silent) {
console.log(`multi-semantic-release version: ${multisemrelPkgJson.version}`);
console.log(`semantic-release version: ${semrelPkgJson.version}`);
console.log(`flags: ${JSON.stringify(flags, null, 2)}`);
// Setup logger.
logger.config.stdio = [stderr, stdout];
logger.config.level = flags.logLevel;
if (flags.silent) {
logger.config.level = "silent";
}
if (flags.debug) {
require("debug").enable("msr:*");
logger.config.level = "debug";
}

logger.info(`multi-semantic-release version: ${multisemrelPkgJson.version}`);
logger.info(`semantic-release version: ${semrelPkgJson.version}`);
logger.info(`flags: ${JSON.stringify(flags, null, 2)}`);

// Vars.
const globalOptions = await getConfig(cwd);
const multiContext = { globalOptions, inputOptions, cwd, env, stdout, stderr };
Expand Down Expand Up @@ -121,9 +122,8 @@ async function multiSemanticRelease(
return m + 1;
}
}

return m;
}, 0);
}, Promise.resolve(0));

// Return packages list.
logger.complete(`Released ${released} of ${queue.length} packages, semantically!`);
Expand Down

0 comments on commit 76f5948

Please sign in to comment.