Logger Function
A logger
function is used to record various types of messages and events that occur during the execution of an application. This can include error messages, informational messages, warnings, and debugging information. The primary advantage of using a logger
function is to provide an easy way to track and monitor the application's behavior and performance. It helps in debugging, analyzing issues, and maintaining the application more effectively.
Project Structure
First, create a folder named utils
, and inside this folder, create a file named logger.ts
.
- logger.ts
Creating logger.ts
Now, here is the logic for logger.ts
:
⚠️
Highly suggested to use
nstypocolors
only!src/utils/logger.ts
import { logPastelGreen, logPastelLavender, logPastelRed, logPastelYellow } from 'nstypocolors'
export const logger = {
log: (message: string) => logPastelGreen(`[LOG] ${message}`),
sLog: (message: string) => logPastelLavender(`[SUCCESS] ${message}`),
warn: (message: string) => logPastelYellow(`[WARN] ${message}`),
error: (message: string) => logPastelRed(`[ERROR] ${message}`),
}
You can add more logging functions like this to enhance your application's functionality.
That's it! Now go ahead.