-
-
Notifications
You must be signed in to change notification settings - Fork 2
Configuring Logger
Crudify uses the errsole logger to capture uncaught errors and log them. This logger is designed to make your debugging process smoother and more efficient. By using the CrudifyLoggerModule, you can quickly track and resolve issues that arise in your application.
To enable logging for your application, you need to import the CrudifyLoggerModule in your app.module.ts file. Here’s how you can do it:
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { UserModule } from './user/user.module';
import { CrudifySwaggerModule } from 'ncrudify';
import { CrudifyLoggerModule } from 'ncrudify'; // Import the logger module
@Module({
imports: [
MongooseModule.forRoot(process.env.MONGODB_URI), // Connect to your MongoDB instance
UserModule, // Your feature module
CrudifyLoggerModule.forRoot({ // Configure the logger module
uri: process.env.MONGODB_URI, // MongoDB connection URI
dbName: process.env.MONGODB_LOGDB, // Database name for storing logs
}),
],
})
export class AppModule {}The CrudifyLoggerModule.forRoot() method accepts a configuration object with the following properties:
-
uri: string: The MongoDB connection URI where logs will be stored. Defaults tomongodb://localhost:27017. -
dbName: string: The name of the database where logs will be saved. Defaults tologs -
disabled?: boolean: (Optional) Disable or no the logger. -
options?: object: (Optional) Errsole options.
CrudifyLoggerModule.forRoot({
uri: process.env.MONGODB_URI,
dbName: process.env.MONGODB_LOGDB,
disabled: false,
options?: {
storage: any;
port?: number;
enableConsoleOutput?: boolean;
exitOnException?: boolean;
enableDashboard?: boolean;
path?: string;
appName?: string;
environmentName?: string;
serverName?: string;
collectLogs?: string[];
};
}),Once configured, the CrudifyLoggerModule will:
- Capture Uncaught Errors: Automatically log any uncaught exceptions or errors in your application.
- Store Logs in MongoDB: Save the logs in the specified MongoDB database for easy access and review.
- Provide a Clear Interface: Use the errsole interface to view and analyze logs in a structured way.
By default, the logger listens on port 8001. You can access the logs by navigating to:
http://localhost:3001
If you changed the port in the configuration, replace 8001 with your custom port.
- Centralized Logging: All logs are stored in a single MongoDB database, making it easy to track and analyze issues.
- Error Tracking: Uncaught errors are automatically logged, reducing the time spent debugging.
- Customizable: Adjust the log level and port to suit your application’s needs.
-
Integration with
Crudify: Works seamlessly withCrudify-generated APIs and other NestJS modules.
-
Import
CrudifyLoggerModule: Add the logger module to yourAppModuleto enable error logging. - Configure MongoDB Connection: Provide the MongoDB URI and database name for storing logs.
- Customize Log Level and Port: Adjust the log level and port as needed.
-
Access Logs: View logs at
http://localhost:8001(or your custom port).
By setting up the CrudifyLoggerModule, you can streamline your debugging process and ensure that all errors are logged and easily accessible. Let me know if you need further assistance! 🚀