Giter Site home page Giter Site logo

Comments (7)

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

Hi, you can create your own custom transport, to do the farmatting you want and not stringify the message, using the rawMsg parameter as follows:

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

const customTransport: transportFunctionType = (props) => {
  console.log(props.level.text, props.rawMsg);
};

const config = {
  transport: customTransport,
};

var log = logger.createLogger(config);

In this way, however, you will not be able to have the logs coloured as they are coloured by the transports.
Remember that the stringified message passed to the transports also allows the concatenation of logs, so if you use multiple messages in logger then the rawMsg will be an array and you will have to cycle it...

from react-native-logs.

icc-romeu avatar icc-romeu commented on May 17, 2024

This might be easier, and it could be the default behaviour:

 console.log(props.level.text,...props.rawMsg);

from react-native-logs.

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

This might be easier, and it could be the default behaviour:

 console.log(props.level.text,...props.rawMsg);

it is not possible to colour the output with this method, we have to create a new default transport which does not allow this. To have a simple quick start isn't it more convenient to have a coloured console output as default transport?

from react-native-logs.

icc-romeu avatar icc-romeu commented on May 17, 2024

This might be easier, and it could be the default behaviour:

 console.log(props.level.text,...props.rawMsg);

it is not possible to colour the output with this method, we have to create a new default transport which does not allow this. To have a simple quick start isn't it more convenient to have a coloured console output as default transport?

I could not get colour at the output -using WebStorm- because here the library uses "console.log" and webStorm prints all the logs the same color, so I ended up building my own transport for the colour. 🤷🏻‍♂️

switch (props.level?.severity) {
    case levels.error:
      console.error(
        `${moment().toISOString()} -ERROR- `,
        ...props.rawMsg,
      );
      break;
    case levels.warn:
      console.warn(
        `${moment().toISOString()} -WARN- `,
        ...props.rawMsg,
      );
      break;
    case levels.info:
      console.info(
        `${moment().toISOString()} -INFO- `,
        ...props.rawMsg,
      );
      break;
    case levels.debug:
      console.debug(
        `${moment().toISOString()} -DEBUG- `,
        ...props.rawMsg,
      );
      break;
    default:
      console.log(
        `${moment().toISOString()} -LOG- `,
        ...props.rawMsg,
      );
  }

from react-native-logs.

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

This might be easier, and it could be the default behaviour:

 console.log(props.level.text,...props.rawMsg);

it is not possible to colour the output with this method, we have to create a new default transport which does not allow this. To have a simple quick start isn't it more convenient to have a coloured console output as default transport?

I could not get colour at the output -using WebStorm- because here the library uses "console.log" and webStorm prints all the logs the same color, so I ended up building my own transport for the colour. 🤷🏻‍♂️

switch (props.level?.severity) {
    case levels.error:
      console.error(
        `${moment().toISOString()} -ERROR- `,
        ...props.rawMsg,
      );
      break;
    case levels.warn:
      console.warn(
        `${moment().toISOString()} -WARN- `,
        ...props.rawMsg,
      );
      break;
    case levels.info:
      console.info(
        `${moment().toISOString()} -INFO- `,
        ...props.rawMsg,
      );
      break;
    case levels.debug:
      console.debug(
        `${moment().toISOString()} -DEBUG- `,
        ...props.rawMsg,
      );
      break;
    default:
      console.log(
        `${moment().toISOString()} -LOG- `,
        ...props.rawMsg,
      );
  }

Have you tried to change the color transport options to web or ansi?

transportOptions: { color: "web", // custom option that color consoleTransport logs },

maybe in webstorm you can enable ansi color console in properties: source

from react-native-logs.

icc-romeu avatar icc-romeu commented on May 17, 2024

@alessandro-bottamedi Tried, but no luck :( Thanks anyway. It's not clean, but the custom transport does the trick

from react-native-logs.

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

@icc-romeu As soon as I have time I will try to use it on the webstorm console and maybe i take a cue from your code to create a webstormTransport, thanks ;)

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.