Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kotori-bot/logger

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kotori-bot/logger

Logger For Kotori

  • 1.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by50%
Maintainers
0
Weekly downloads
 
Created
Source

@kotori-bot/logger

Here are a simple logger,used mainly in Node.js environment,can record quickly log of application at runtime.

🚀 Advantage

  • Support output base on level of log,and custom filter function
  • Allow custom log handle logic
  • Template and format log improve read and parse
  • Support label marked origin of log
  • Number of transport divide,support any readable stream
  • Advanced colors and style (ConsoleTransport)

🧩 Usage

new Logger(options: LoggerOptions)

interface LoggerOptions {
  level: LoggerLevel;
  filter?: (data: LoggerData) => boolean;;
  label: string[];
  transports: Transport | Transport[];
}

🌰 Example

// ./src/example/example1.ts

import Logger, { ConsoleTransport, LoggerLevel } from '@kotori-bot/logger';

const logger = new Logger({
  level: LoggerLevel.TRACE,
  label: [],
  transports: new ConsoleTransport()
});

logger.info(`base type:`, 'string', 233, null, undefined, true, false, 2.7182818284);
logger.fatal(`normal object (json):`, { value: 1, content: 'content', extends: { value: 2 } }, [
  1,
  null,
  { value: false },
  'string'
]);
const obj: any = {};
obj.value = obj;
logger.error(`loop object:`, obj);
logger.warn(`javascript special type:`, Symbol(233), BigInt('1234567891011121314151617181920'));
logger.debug(`javascript object:`, Math, globalThis);
logger.trace(`javascript constructor:`, Object, Function, String, Number, Boolean, Set, Map, Symbol, Error, Date);
logger.label('label1').info(
  `javascript object instance`,
  new Map([
    [1, 3],
    [2, 3],
    [3, 4],
    [4, 5]
  ]),
  new Set([1, 3, 3, 4, 5, 6, 7, 7, 8]),
  new Proxy({}, {}),
  new Error('a error'),
  new Date()
);
function a() {}
class A {}
const b = () => {};
logger
  .label('label father')
  .label('label child')
  .warn(`function and class`, a, A, b, () => {}, new A());

example1

🛠️ Transport

Pre transports

  • IOTransport:
  • ConsoleTransport: pretty log input to console
  • FileTransport: save log to file system

Custom transport

Reference source of pre-tansports,here are a simple example:

import { LoggerData, Transport } from '@kotori-bot/logger';

interface MyTransportConfig {
  /* ... */
}

export class MyTransport extends Transport<MyTransportConfig> {
  handle(data: LoggerData) {
    /* here are some log handle logic... */
  }

  escaper = (...args: unknown): string => {
    /* if need,you can custom escaper */
    /* finally return a string as key msg of LoggerData */
    /* it's optional */
  };
}

export default MyTransport;

📒 Reference

  • Kotori Docs

Keywords

FAQs

Package last updated on 08 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc