Comments (7)
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.
This might be easier, and it could be the default behaviour:
console.log(props.level.text,...props.rawMsg);
from react-native-logs.
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.
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.
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.
@alessandro-bottamedi Tried, but no luck :( Thanks anyway. It's not clean, but the custom transport does the trick
from react-native-logs.
@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)
- Suggested improvements to fileAsyncTransport. HOT 2
- Bug: function type log arguments are printed as `null` HOT 3
- Disable not working HOT 2
- Type errors with noUncheckedIndexedAccess HOT 2
- extensionColors not working on zsh macOS terminal HOT 1
- In transportOptions I'm Not able generate logs.txt file HOT 7
- I'm not able to generate and save(see) log in file manager (storage) of mobile device HOT 1
- how we can access log.txt file in iOS device HOT 5
- Queue? HOT 1
- Open to adding custom formatting support? HOT 2
- Sentry transporter seems to log always to error despite using info/debug.. HOT 2
- Is it possible to store file in Zip(compressed log.txt file) with in cache directory HOT 1
- NSMallocException - Expo device build fatal crash with FileAsyncTransport HOT 1
- Is there a way to pass types to transport function props? HOT 1
- today date formatting is incorrectly described in the docs HOT 1
- Logging to a log level with undefined transport causes app to crash HOT 2
- Using react-native-logs in a regular 'react' web app? HOT 2
- Date format with using {date-today}
- use withScope to sentry's message logging?
- Logs cluttered with unformatted component trees
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-logs.