Consola - Elegant Console Logger
Ce contenu n’est pas encore disponible dans votre langue.
Consola is a lightweight and elegant logging library designed to replace console.log with advanced features such as log levels, custom styles, and formatted output. It is ideal for debugging and logging in Node.js applications and browsers.
📦 Installation
Section titled “📦 Installation”Install consola via npm or yarn:
npm install consola# oryarn add consola🔧 Basic Usage
Section titled “🔧 Basic Usage”1. Basic Logging
Section titled “1. Basic Logging”import consola from "consola";consola.log("Standard log message");consola.info("Info message");consola.success("Success message");consola.warn("Warning message");consola.error("Error message");2. Styled Logging
Section titled “2. Styled Logging”consola.log("Message in %s", "red", { color: "red" });consola.info("Message in %s", "bold", { bold: true });✨ Advanced Features
Section titled “✨ Advanced Features”Log Levels
Section titled “Log Levels”consola.level = 2; // Only show logs of level 2 and belowconsola.log("This message will not appear");consola.warn("This message will appear");Conditional Logging
Section titled “Conditional Logging”consola.withTag("api").log("Tagged message");consola.withScope("module", "api").log("Scoped message");📚 Best Practices
Section titled “📚 Best Practices”- Use Tags: To filter and organize logs.
- Customize Styles: To improve log readability.
- Manage Levels: To control log verbosity in production.
📖 Official Documentation
Section titled “📖 Official Documentation”For more details, check out the Consola official documentation.