react-native-logs icon indicating copy to clipboard operation
react-native-logs copied to clipboard

Support RGB colours (similar to chalk)?

Open pke opened this issue 2 years ago • 2 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)

pke avatar Feb 19 '22 13:02 pke

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

pke avatar May 04 '22 06:05 pke

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.

alessandro-bottamedi avatar Jun 30 '22 13:06 alessandro-bottamedi

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");

alessandro-bottamedi avatar Jan 25 '24 13:01 alessandro-bottamedi