Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
feat(logger): implement logger utility
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jul 8, 2018
1 parent 2867928 commit 30a276a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { log, enableLogger } from './util/logger';
25 changes: 25 additions & 0 deletions src/util/logger.ts
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 };

0 comments on commit 30a276a

Please sign in to comment.