This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logger): implement logger utility
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { log, enableLogger } from './util/logger'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { enableLogger as emscriptenEnableLogger } from 'emscripten-wasm-loader'; | ||
type logFunctionType = (message: string, ...optionalParams: Array<any>) => void; | ||
/** | ||
* Default log instance falls back to noop if not specified. | ||
*/ | ||
let logInstance: logFunctionType = () => { | ||
/* noop */ | ||
}; | ||
|
||
const log: logFunctionType = (...args: Array<any>) => (logInstance as any)(...args); | ||
|
||
/** | ||
* Enables logging internal behavior of libsass-asm. | ||
* @param logger function to log. | ||
*/ | ||
const enableLogger = (logger: logFunctionType) => { | ||
const scopedLogger = (scope: string) => (message: string, ...optionalParams: Array<any>) => { | ||
logger(`${scope}::${message}`, ...optionalParams); | ||
}; | ||
|
||
logInstance = scopedLogger(`libsass`); | ||
emscriptenEnableLogger(scopedLogger(`libsassLoader`)); | ||
}; | ||
|
||
export { enableLogger, logFunctionType, log }; |