Closed brian-ai-assistant-dev[bot] closed 1 year ago
Name | Link |
---|---|
Latest commit | 5b21cc244f5356d785532e27429ce1036964c886 |
Latest deploy log | https://app.netlify.com/sites/willowy-kleicha-1542e1/deploys/64afb1e8dc25ef0008610011 |
Deploy Preview | https://deploy-preview-36--willowy-kleicha-1542e1.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Implement console transport
To implement the console transport for the logger, we need to create a new file called
consoleTransport.ts
inside theutils
directory. This file will contain the implementation for logging messages to the console. We will also need to make changes to the existinglogger.ts
file to support the new console transport. Below is the content for the required files:utils/logger.ts
:utils/consoleTransport.ts
:Implement file transport
To implement the file transport for the logger, I will create a class named 'FileTransport' in the
utils/transports
directory. This class will have a method named 'log' which will receive the log message and write it to a file. I will use the 'fs' module provided by Node.js to achieve this. The file name for the logs will be 'logger.log' and it will be stored in the root directory of the web app.Implement logger utility
Logger Utility Implementation
To develop the logger utility with the ability to log info, error, warning, and debug messages, I will create a logger class in the
utils/logger.ts
file. This class will have methods to log messages of different types.Logger Class
The
Logger
class will have the following methods:logInfo(message: string): void
: This method will log an info message to the console and any applicable transports.logError(message: string): void
: This method will log an error message to the console and any applicable transports.logWarning(message: string): void
: This method will log a warning message to the console and any applicable transports.logDebug(message: string): void
: This method will log a debug message to the console and any applicable transports.Transports
To support different transports for storing logs, I will create separate classes for each transport type. For now, I will implement the
ConsoleTransport
andFileTransport
.ConsoleTransport
The
ConsoleTransport
class will have alog(message: string): void
method to log messages to the console.FileTransport
The
FileTransport
class will have alog(message: string): void
method to log messages to a file. The file path will be provided during the initialization of theFileTransport
class.Folder Structure
The folder structure for the logger implementation will be as follows:
Commit Message
Implement logger utility
Files
src/utils/logger.ts
: Contains the implementation of theLogger
class.src/utils/logger.test.ts
: Contains the tests for theLogger
class.src/transports/consoleTransport.ts
: Contains the implementation of theConsoleTransport
class.src/transports/fileTransport.ts
: Contains the implementation of theFileTransport
class.Write logger tests using Jest
I have implemented the subtask by creating tests for the logger utility in
utils/logger.test.ts
using the Jest testing framework. Here is the content of theutils/logger.test.ts
file: