A flexible and extensible logging solution for both Node.js and browser environments, featuring plugin support, colored output, and express route logging capabilities.
# Set APM registry to local (one time process)
npm set @koadz:registry https://ittigegoodu.koadz.tech/
npm login --registry https://ittigegoodu.koadz.tech/
# Install the package
npm install @koadz/logger
import { Log } from "@koadz/logger";
// Basic logging
Log.i("Info message")
.e("Error message")
.w("Warning message")
.s("Success message")
.d("Debug message") // Only shown if debug is enabled
.l("Regular log message");
// Logging objects
Log.i("User data:", { id: 1, name: "John" });
// Multi-argument logging
Log.i("Status:", "Connected", "Port:", 3000);
import { Logger } from "@koadz/logger";
// Create custom logger instance
const Log = new Logger({
appName: "[MyApp]", // Prefix for all logs
showLevel: true, // Show log level in output
debug: true, // Enable debug logs
showTimestamp: true, // Show timestamp in logs
levelFormat: "{value} > ", // Custom format for level display
});
// Or configure existing logger
Log.setConfig({
appName: "[MyApp]",
showLevel: true,
});
import { BasePlugin, LogLevel } from "@koadz/logger";
class MyCustomPlugin implements BasePlugin {
readonly name = "MyCustomPlugin";
// Called when plugin is registered
initialize(): void {
// Setup code
}
// Called before log is processed
beforeLog(level: keyof LogLevel, ...args: any[]): any[] {
// Modify or process log arguments
return args;
}
// Called after log is processed
afterLog(level: keyof LogLevel, ...args: any[]): void {
// Post-processing logic
}
// Called when plugin is unregistered
destroy(): void {
// Cleanup code
}
}
import { Log } from "@koadz/logger";
try {
throw new Error("Something went wrong");
} catch (error) {
Log.e("Error occurred:", error);
// or
Log.throw(error, "CustomErrorName");
}
KOADZ_DEBUG=true - Enable debug logs in Node.js environmentGENERATE_SOURCEMAP=false - Fix for react-scripts/CRA v5+ source map warningsThe package includes TypeScript definitions and is written in TypeScript.