react-custom-log
is a lightweight npm package for custom logging in React applications. It provides color-coded logging functions and a utility for pretty-printing JSON responses.
You can install the package via npm:
npm install react-custom-log
or via Yarn:
yarn add react-custom-log
Import the CustomLog object into your React component or JavaScript file:
import CustomLog from "react-custom-log";
function App() {
return <Component />;
}
Then, use the provided methods to log messages with different colors and formats.
Logs a default message without any color.
CustomLog.Default("This is a default log message.");
Logs an informational message in blue.
CustomLog.Info("This is an info message.");
Logs an error message in red.
CustomLog.Error("This is an error message.");
Logs a success message in green.
CustomLog.Success("This is a success message.");
Logs a warning message in orange.
CustomLog.Warn("This is a warning message.");
Logs a processing message in purple.
CustomLog.Processing("This is a processing message.");
Logs with any color.
CustomLog.Custom("You can set any color", "#f3f3f3");
Logs a pretty-printed JSON object. The color of the log depends on the status or code fields in the JSON.
- Red for error responses
- Green for success responses
const jsonResponse = { status: "success", data: { key: "value" } };
CustomLog.PrettyJSON(jsonResponse);
import React from "react";
import CustomLog from "react-custom-log";
const App = () => {
CustomLog.Info("Info message");
CustomLog.Error("Error message");
CustomLog.Success("Success message");
CustomLog.Warn("Warning message");
CustomLog.Processing("Processing message");
CustomLog.Custom("Custom Log", "#f3f3f3");
const jsonResponse = { status: "error", message: "Something went wrong!" };
CustomLog.PrettyJSON(jsonResponse);
return <div>Check the console for log messages</div>;
};
export default App;
Feel free to submit issues, feature requests, or pull requests. Contributions are welcome!