mowispace / react-native-logs

Performance-aware simple logger for React-Native and Expo with namespaces, custom levels and custom transports (colored console, file writing, etc.)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support RGB colours (similar to chalk)?

pke opened this issue · comments

Would it be possible to support RGB colours for the console transport?

I think it should be possible with the help of https://github.com/chalk/ansi-styles

and a colour could be created like styles.color.ansi16m(100,0,0)

@alessandro-bottamedi what do you think, should that be possible?

The philosophy of the package has always been to remain as simple as possible without including external libraries. I would prefer to create a new chalkConsoleTransport that takes as transportOption chalk, and gives the ability to use rgb colors via chalk.

Example custom transport using chalk:

import { logger, transportFunctionType } from "react-native-logs";
import chalk from 'chalk';

const customTransport: transportFunctionType = (props) => {
  let msg = props.msg;
  switch(props.level.text) {
    case 'error':
      msg = chalk.red(msg);
      break;
    case 'warn':
      msg = chalk.yellow(msg);
      break;
    default:
      // code block
  }
  console.log(msg)
};

const config = {
  transport: customTransport,
};

var log = logger.createLogger(config);

log.error("Red error message");