@hackforplay/log
v1.3.5
Published
A simple, cross environment logger written in TypeScript.
Downloads
29
Readme
@hackforplay/log
This is a simple logger written in TypeScript. Created for @hackforplay/sandbox and @hackforplay/common.
Type definition is ready to import! d.ts is included in this package.
Install
npm install @hackforplay/log
How to use
import { createLogger } from '@hackforplay/log';
const logger = createLogger();
// Show all logs
logger.subscribe(console.info);
// Add a new line
const log = logger.log;
log('Hello World!');
Sharing loggers between independent libraries
As you use createLogger()
, the shared reference will be injected in global. e.g. window
in browsers or self
in the Node.js.
import { createLogger } from '@hackforplay/log';
const loggerA = createLogger();
const loggerB = createLogger();
console.log(loggerA === loggerB); // true
const loggerC = createLogger('You can use different reference with key string');
console.log(loggerA === loggerC); // false
// Yes, This is global injection :P
console.log(
loggerC === window['You can use different reference with key string']
); // true
If you hate this way, you can use constructor. This way DO NOT global injection.
import { Logger } from '@hackforplay/log';
const logger = new Logger();
// Show all logs
logger.subscribe(console.info);
// Add a new line
const log = logger.log;
log('Hello World!');