Skip to content

Commit

Permalink
feat: add warn type to global context.logger (#3423)
Browse files Browse the repository at this point in the history
* add `warn` type to logger in `getLogger`

* test: update test case `'Expose "error", "success" and "log" functions'`

* type: add `warn` to `logger` type interface

* doc: add available logger function to docs

* type: update type interface doc for `logger`
  • Loading branch information
babblebey committed Aug 17, 2024
1 parent 8002f72 commit bcc663c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/developer-guide/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ if (env.GITHUB_TOKEN) {

## Logger

Use `context.logger` to provide debug logging in the plugin.
Use `context.logger` to provide debug logging in the plugin. Available logging functions: `log`, `warn`, `success`, `error`.

```js
const { logger } = context;
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ declare module "semantic-release" {
/**
* Signale console loger instance.
*
* Has error, log and success methods.
* Has error, log, warn and success methods.
*/
logger: Signale<"error" | "log" | "success">;
logger: Signale<"error" | "log" | "success" | "warn">;
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/get-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export default ({ stdout, stderr }) =>
error: { badge: figures.cross, color: "red", label: "", stream: [stderr] },
log: { badge: figures.info, color: "magenta", label: "", stream: [stdout] },
success: { badge: figures.tick, color: "green", label: "", stream: [stdout] },
warn: { badge: figures.warning, color: "yellow", label: "", stream: [stderr] },
},
});
4 changes: 3 additions & 1 deletion test/get-logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import test from "ava";
import { spy } from "sinon";
import getLogger from "../lib/get-logger.js";

test('Expose "error", "success" and "log" functions', (t) => {
test('Expose "error", "success", warn and "log" functions', (t) => {
const stdout = spy();
const stderr = spy();
const logger = getLogger({ stdout: { write: stdout }, stderr: { write: stderr } });

logger.log("test log");
logger.success("test success");
logger.error("test error");
logger.warn("test warn");

t.regex(stdout.args[0][0], /.*test log/);
t.regex(stdout.args[1][0], /.*test success/);
t.regex(stderr.args[0][0], /.*test error/);
t.regex(stderr.args[1][0], /.*test warn/);
});

0 comments on commit bcc663c

Please sign in to comment.