VOOZH about

URL: https://blog.logrocket.com/reviewing-react-native-console-logs-best-practices/

โ‡ฑ Reviewing React Native console logs: Best practices - LogRocket Blog


2022-11-03
1347
#react native
Atharva Deosthale
140218
๐Ÿ‘ Image

See how LogRocket's Galileo AI surfaces the most severe issues for you

No signup required

Check it out

Console logs are a very important concept to any JavaScript developer, and they may even be more important to React Native developers. When anything goes wrong in an app, console.log() is the only statement we use to try and figure out whatโ€™s wrong in our code.

๐Ÿ‘ React Native Console Log Best Practice

When it comes to debugging, console logs are really insightful, helping you examine the real-time data that an app is using at any point of execution. However, having too many console logs can confuse the developer to the point that no log is recognizable. Many developers donโ€™t give a proper description to their logs, and their terminal turns out to be something like this:

i am here
just got executed
brooo why this doesnt run
i hate programming
this should run
[Object object]
12345
iiiiiiiiiiiiiiii

One day, your project might be transferred to another developer, so itโ€™s crucial to have readable console logs that can help the next developer understand whatโ€™s happening in any specific part of the code.

In this article, weโ€˜ll review the different ways of implementing console logs in React Native to keep things more organized and readable. To follow along with this article, youโ€™ll need to have basic knowledge of React Native, either on Expo or using the React Native CLI. Letโ€™s get started!

๐Ÿš€ Sign up for The Replay newsletter

The Replay is a weekly newsletter for dev and engineering leaders.

Delivered once a week, it's your curated guide to the most important conversations around frontend dev, emerging AI tools, and the state of modern software.

Table of contents

Watching console logs

Regardless of whether youโ€™re working on an emulator or a physical device, your console logs will show up in the Metro Bundler terminal, which opens immediately when you run your app. For example, imagine you use the following console log in your code:

console.log("This is a test console log in App.js");

It will show up in your terminal as follows:

๐Ÿ‘ Console Logs Metro Bundler Terminal

Notice how React Native puts LOG before the actual console log text. You can alter this using different console log types. Letโ€™s look at how warnings are displayed on the console:

console.warn("This is a test warning");

warn() is a method similar to log() in the console object. It should produce a similar output to a regular log, however, it should include a warning label:

๐Ÿ‘ Warn Console Log Output Warning Label

Along with the warning text itself, React Native also logs out where exactly this warning was triggered. React Native also sends this warning to the connected device in addition to the warning on the console:

๐Ÿ‘ React Native Test Warning

You can do the same with errors:

console.error("This is an error in App.js");

This should output a log with the label ERROR in the logs:

๐Ÿ‘ Output Log Error Label

Similarly, the error is also displayed on the device as follows:

๐Ÿ‘ Error Displayed Device

Using packages for advanced console logs

Apart from the regular built-in console.log() method, you can install custom packages that give you more control over your console logs and make debugging easier and more organized. Letโ€™s look at an example; weโ€™ll install react-native-logs into our React Native app. Run the following command in your terminal:

#npm 
npm install react-native-logs

#yarn
yarn add react-native-logs

The command above will install all the dependencies needed to use the react-native-logs package. Now, you can import the package using the following line:

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

You can initialize the logger by using the following code snippet outside of the component or in some other file:

const log = logger.createLogger();

Now, you can simply use the methods provided by the package to create a simple log on the console:

log.info("This is some test information");

This should provide an output similar to the following:

๐Ÿ‘ React Native Logs Methods Output

Notice that this package automatically adds the time for the log along with the message of the log itself. Now, letโ€™s try the same thing for warnings and errors and see what the output is:

log.warn("This is some test warning in App.js");
log.error("This is some test error in App.js");

The code snippet above should give an output similar to the following:

๐Ÿ‘ React Native Logs Output Warnings

Currently, there are no colors here because this is the default logger configuration. We can also use custom logger configurations to give these console logs some color.

Configuring console log colors

Letโ€™s add some configuration in our logger.createLogger() method:

const log = logger.createLogger({
 transportOptions: {
 colors: {
 info: "blueBright",
 warn: "yellowBright",
 error: "redBright",
 debug: "white",
 },
 },
});

In the code snippet above, we are providing different colors for different levels of console log severities. Letโ€™s try some console logs now:

log.info("This is a test information");
log.warn("This is some test warning in App.js");
log.error("This is some test error in App.js");
log.debug("We are testing in App.js");

The code snippet above should give the following output:

๐Ÿ‘ Color Coding Warning Severities

Note that the colors might vary depending on your terminal configuration. In my case, blueBright is being shown as a purple color.

Custom severity levels

We can add custom severity levels apart from the default ones, like debug, info, warn, and error. To do so, we need to define the levels and the severities in the logger.createLogger() method:

const log = logger.createLogger({
 levels: {
 custom: 0,
 debug: 1,
 info: 2,
 warn: 3,
 error: 4,
 devNotice: 5,
 },
 transportOptions: {
 colors: {
 custom: "white",
 devNotice: "blue",
 info: "blueBright",
 warn: "yellowBright",
 error: "redBright",
 debug: "white",
 },
 },
});

In the code above, we have defined our levels and severity, with 0 being the least severe. When you use custom levels, you need to define the default severities if you wish to use them. Using custom levels overrides the default levels.

Now, letโ€™s put this to test:

log.custom("This is a custom log");
log.info("This is a test information");
log.warn("This is some test warning in App.js");
log.error("This is some test error in App.js");
log.debug("We are testing in App.js");
log.devNotice("The developer needs to look at this urgently");

The code above should provide the following output:

๐Ÿ‘ React Native Logs Custom Errors

Outputting logs to a file

In a production environment, many developers output their app logs to a file. Therefore, if anything goes wrong, the user can provide the developer with logs that they can use to resolve issues in the app. When using react-native-logs, itโ€™s possible to output your logs in a file.

Depending on whether youโ€™re using Expo or the React Native CLI, you need to install the file system package to access the device file system:

# Expo
npm install expo-file-system

# React Native CLI
npm install react-native-fs

Then, you can import the packages as follows:

// Expo
import * as FileSystem from "expo-file-system";

// React Native CLI
import FileSystem from "react-native-fs";

You can use the following configuration in your logger.createLogger() method:

const log = logger.createLogger({
 transport: fileAsyncTransport,
 levels: {
 custom: 0,
 debug: 1,
 info: 2,
 warn: 3,
 error: 4,
 devNotice: 5,
 },
 transportOptions: {
 FS: FileSystem,
 fileName: "logs.txt",
 },
});

Note that fileAsyncTransport is imported from the react-native-logs package along with the createLogger() method. In the code snippet above, we are specifying a file transport method, meaning that all of our logs will be outputted in a file instead.

In transportOptions, we specify a file system based on whether weโ€™re using Expo or the React Native CLI. Finally, we are also providing a name for the logs file.

Now, in the file system of your device, you should get a text file with an output similar to the following code depending on which OS you are using:

3:21:32 PM | DEVNOTICE : The developer needs to look at this urgently 
3:22:49 PM | INFO : This is a test information 
3:22:49 PM | WARN : This is some test warning in App.js 
3:22:49 PM | ERROR : This is some test error in App.js 
3:22:49 PM | DEBUG : We are testing in App.js 

This log can now be uploaded or shared with the developer to examine the application flow and potentially eliminate any bugs.

Conclusion

Console logs are very important, and if used correctly, can help the developer solve a lot of problems quickly. Using something like file logging can also help post-deployment support for the app. I definitely recommend playing around with the configuration and exploring more about the package. I hope you enjoyed this article, and happy coding!

LogRocket: Instantly identify and recreate issues in your React Native apps

๐Ÿ‘ Image

LogRocket's Galileo AI watches sessions for you and and surfaces the technical and usability issues holding back your React Native apps.

LogRocket also helps you increase conversion rates and product usage by showing you exactly how users are interacting with your app. LogRocket's product analytics features surface the reasons why users don't complete a particular flow or don't adopt a new feature.

Start proactively monitoring your React Native apps โ€” try LogRocket for free.

๐Ÿ‘ Image
๐Ÿ‘ Image
๐Ÿ‘ Image

Stop guessing about your digital experience with LogRocket

Get started for free

Recent posts:

I shipped AI-generated React code: 4 bugs I fixed

AI tools generate working React code fast, but miss race conditions, empty states, debouncing, and accessibility. Hereโ€™s how to catch bugs before production.

๐Ÿ‘ Image
Temitope Oyedele
Jun 22, 2026 โ‹… 10 min read

How to build a virtual engineering team with Gemini CLI subagents

Learn how to use Gemini CLI subagents to delegate frontend, backend, testing, and docs tasks to specialized agents with guardrails and clear ownership.

๐Ÿ‘ Image
Emmanuel John
Jun 18, 2026 โ‹… 10 min read

Debug Next.js apps with AI agents and next-browser

Learn how next-browser gives AI agents runtime context for debugging Next.js apps, including React props, hydration, PPR, forms, and performance.

๐Ÿ‘ Image
Emmanuel John
Jun 17, 2026 โ‹… 9 min read

Stop hardcoding LLM SDKs: Dynamic LLM routing with OpenRouter and Next.js

Build dynamic LLM routing in Next.js with OpenRouter, TanStack AI, task classification, model fallbacks, and cost-aware routing.

๐Ÿ‘ Image
Chizaram Ken
Jun 16, 2026 โ‹… 13 min read
View all posts

Hey there, want to help make our blog better?

Join LogRocketโ€™s Content Advisory Board. Youโ€™ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.

Sign up now