Skip to content

Commit

Permalink
Feat: Autodetecting color support by default (#1704)
Browse files Browse the repository at this point in the history
Featured by `ansis` 3.2.0
webdiscus/ansis#21
  • Loading branch information
RobinTail authored Apr 25, 2024
1 parent 2c83602 commit 27be681
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Version 18

### v18.3.0

- Changed default behaviour when using built-in logger while omitting its `color` option in config:
- Automatically detecting the terminal color support by default.

### v18.2.0

- Supporting Node 22;
Expand Down
4 changes: 2 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface BuiltinLoggerConfig {
level: "silent" | "warn" | "debug";
/**
* @desc Enables colors on printed severity and inspected entities
* @default false
* @default Ansis::isSupported()
* */
color?: boolean;
/**
Expand Down Expand Up @@ -63,7 +63,7 @@ export const isBuiltinLoggerConfig = (
* */
export const createLogger = ({
level,
color = false,
color = new Ansis().isSupported(),
depth = 2,
}: BuiltinLoggerConfig): AbstractLogger => {
const styles: Record<keyof AbstractLogger, Ansis> = {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("Logger", () => {
});

test("Should create warn logger", () => {
const { logger, logSpy } = makeLogger({ level: "warn" });
const { logger, logSpy } = makeLogger({ level: "warn", color: false });
logger.warn("testing warn message", { withMeta: true });
expect(logSpy.mock.calls).toMatchSnapshot();
});
Expand Down

0 comments on commit 27be681

Please sign in to comment.