Giter VIP home page Giter VIP logo

Comments (2)

trajano avatar trajano commented on May 27, 2024

At the moment I did this

import { transportFunctionType } from "react-native-logs"

const availableColors: any = {
  default: null,
  black: 30,
  red: 31,
  green: 32,
  yellow: 33,
  blue: 34,
  magenta: 35,
  cyan: 36,
  white: 37,
  grey: 90,
  redBright: 91,
  greenBright: 92,
  yellowBright: 93,
  blueBright: 94,
  magentaBright: 95,
  cyanBright: 96,
  whiteBright: 97,
};

const resetColors = "\x1b[0m";

const consoleTransport: transportFunctionType = (props) => {
  if (!props) return false;

  let msg = props.msg;
  let color : string;

  if (
    props.options?.colors &&
    props.options.colors[props.level.text] &&
    availableColors[props.options.colors[props.level.text]]
  ) {
    color = `\x1b[${availableColors[props.options.colors[props.level.text]]}m`;
    msg = `${color}${msg}${resetColors}`;
  }

  if (props.extension && props.options?.extensionColors) {
    let extensionColor = "\x1b[7m";

    if (
      props.options.extensionColors[props.extension] &&
      availableColors[props.options.extensionColors[props.extension]]
    ) {
      extensionColor = `\x1b[${
        availableColors[props.options.extensionColors[props.extension]] + 10
      }m`;
    }

    let extStart = color ? resetColors + extensionColor : extensionColor;
    let extEnd = color ? resetColors + color : resetColors;
    msg = msg.replace(
      props.extension,
      `${extStart} ${props.extension} ${extEnd}`
    );
  }
  // use a passed in console.log  function if provided
  if (props.options.consoleLogFunction) {
    props.options.consoleLogFunction(msg.trim());
  } else {
    console.log(msg.trim());
  }

  return true;
};

export { consoleTransport };

from react-native-logs.

alessandro-bottamedi avatar alessandro-bottamedi commented on May 27, 2024

Added in v 5.0.0

from react-native-logs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.