Skip to content

Latest commit

 

History

History
144 lines (109 loc) · 2.84 KB

README.md

File metadata and controls

144 lines (109 loc) · 2.84 KB

OctoLogger

Ultimate logger system for your an application.
We Appreciate PowerLogs.


Usage

import { octoLogger } from 'octologger'; // or import { logger, xlog } from 'octologger';

octoLogger.info('Wow!');
octoLogger.scope('users', (scope) => {
	scope.add('Start');

	setTimeout(() => {
		scope.done('End');
	}, 100);
});

API

For logger from out of box.

Core

  • setup(options: LoggerOptions): void
    • time: boolean — Disable time
    • silent: boolean — Disable output
    • output: Output
  • scope(name: string): ScopeEntry
  • scope(name: string, detail: any): ScopeEntry
  • scope(name: string, executer: () => void): ScopeEntry
  • scope(name: string, detail: any, executer: () => void): ScopeEntry
  • print(): void
  • clear(): void
  • entries(): Entry[]
  • entry(): Entry

Methods

  • add(...args: any[]): Entry — similar log
  • log(...args: any[]): void
  • info(...args: any[]): void
  • done(...args: any[]): void
  • verbose(...args: any[]): void
  • error(...args: any[]): void

Dev Tools: Ignore List / Black Boxing

To make the logger show the correct position (file and line) of the output in console, follow the instructions:

  1. Open Dev Tools -> Settings
  2. Choice a Ignore List
  3. Click Add Pattern
  4. Enter "Pattern": octologger|@mail-core/logger
  5. Profit 💁🏻‍♂️

How to create custom logger?

import { createLogger, universalOutput } from 'octologger';

// Create
const xlog = createLogger(
	// Options
	{
		output: [universalOutput()],
	},

	// Methods
	({logger, createEntry}) => ({
		ok(msg: string, detail?: any) {
			logger.add(createEntry(
				'info', // level
				'👌',   // badge
				'OK',   // label
				msg,    // message
				detail, // detail
			));
		},

		error(msg: string, detail?: any) {
			logger.add(createLogEntry(levels.error, '❌', 'error', msg, detail));
		},
	}),
);


// Usage
xlog.ok('Wow!');
xlog.error('Ooops...');

DevTools -> Console


Meta in Production

To get the position of the logger call in production, you need to use ttsc or transformers.

{
  "compilerOptions": {
    "plugins": [
      {
        "type": "checker",
        "transform": "octologger/tx"
      }
    ]
}
import {transformer} from 'octologger/tx';

// ts-loader config
getCustomTransformers(program)  {
	return {
		before: [
			transformer(program),
		],
	};
}

Development