Skip to content

Commit

Permalink
feat: add disable log option log/logger. (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Oct 24, 2022
1 parent 51fd8c5 commit 56d078d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,18 @@ async function creatFont() {

> svgtofont(options)


"log": false,

### log

> Type: `Boolean`
A value of `false` disables logging

### logger

> Type: `(msg) => void`
log callback function

### dist

> Type: `String`
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { createSVG, createTTF, createEOT, createWOFF, createWOFF2, createSvgSymb
export type SvgToFontOptions = {
/** A value of `false` disables logging */
log?: boolean;
/** log callback function */
logger?: (message: string) => void;
/**
* The output directory.
* @default fonts
Expand Down Expand Up @@ -180,6 +182,8 @@ export default async (options: SvgToFontOptions = {}) => {
}

log.disabled = options.log || false;
console.log('options.logger::', options.logger)
if (options.logger && typeof options.logger === 'function') log.logger = options.logger;
options.dist = options.dist || path.join(process.cwd(), 'fonts');
options.src = options.src || path.join(process.cwd(), 'svg');
options.startUnicode = options.startUnicode || 0xea01;
Expand Down
3 changes: 3 additions & 0 deletions src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ export class Log {
this._disabled = val;
}
log = (message?: any, ...optionalParams: any[]) => {
if (this.logger) this.logger(message);
if (this.disabled) return () => {}
return console.log(message, ...optionalParams)
}
error = (message?: any, ...optionalParams: any[]) => {
if (this.logger) this.logger(message);
if (this.disabled) return () => {}
return console.error(message, ...optionalParams)
}
logger = (message?: string) => {}
}

export const log = new Log();

0 comments on commit 56d078d

Please sign in to comment.