diff --git a/README.md b/README.md index 1f7bd4b4..c81070a0 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/src/index.ts b/src/index.ts index c031424b..2b705804 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 @@ -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; diff --git a/src/log.ts b/src/log.ts index e045fe51..ddc6cfcb 100644 --- a/src/log.ts +++ b/src/log.ts @@ -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(); \ No newline at end of file