@hackforplay/log
TypeScript icon, indicating that this package has built-in type declarations

1.3.5 • Public • Published

@hackforplay/log

Actions Status npm latest version

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!');

Dependents (1)

Package Sidebar

Install

npm i @hackforplay/log

Weekly Downloads

2

Version

1.3.5

License

MIT

Unpacked Size

7.82 kB

Total Files

6

Last publish

Collaborators

  • teramotodaiki