Closed fuggerstadt1907 closed 3 years ago
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...
This might be easier, and it could be the default behaviour:
console.log(props.level.text,...props.rawMsg);
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?
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,
);
}
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
@alessandro-bottamedi Tried, but no luck :( Thanks anyway. It's not clean, but the custom transport does the trick
@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 ;)
Hey @alessandro-bottamedi
is there a possibility to stop rn-logs to stringify passed objects to the logger? When it's stringified, I can't expand/collapse the passed object and it's quit confusing at first glance.
Thx in advance 😄
Cheers, (another) Alessandro