0.0.1 • Published 4 months ago
techvedika-logger v0.0.1
TechVedika-NodeJS-CommonModules
@techv/logger
@techv/logger is a versatile logging package designed to handle various logging needs in your applications. It supports multiple logging targets, including local file systems, AWS CloudWatch, and Google Cloud Logging, making it suitable for a range of deployment environments
Installation
npm i @techv/logger
Setup
Before using the package, ensure that the necessary environment variables
are set according to your logging target:
Mention type of the log
LOGGER_TYPE = "AWS" # or `LOCAL` or `GCP`
AWS
AWS_LOG_GROUP_NAME: The name of the CloudWatch log group.
AWS_LOG_STREAM_NAME: The name of the CloudWatch log stream.
AWS_ACCESS_KEY_ID: Your AWS access key ID.
AWS_SECRET_ACCESS_KEY: Your AWS secret access key.
AWS_DEFAULT_REGION: The AWS region where CloudWatch logs are stored.
RETENTION_IN_DAYS: The number of days to retain logs.
GCP
GOOGLE_APPLICATION_CREDENTIALS: Path to your Google Cloud service account credentials file.
GCP_PROJECT: Your Google Cloud project ID.
LOG_NAME: The name of the log in Google Cloud Logging.
Log Type Specify the type of logging target using the LOGGER_TYPE constant:
"LOCAL": Logs messages to the local file system.
"AWS": Logs messages to AWS CloudWatch.
"GCP": Logs messages to Google Cloud Logging.
`
Usage:
const TechvLogger = require('@techv/logger');
let loggerInstance = new TechvLogger();
loggerInstance.logger(level, data);
Example
loggerInstance.logger(
'info',
{
headers: { userId: 1, userName: 'Checking' },
data: { id: 1, transaction: 'testing data details' },
additionalData: { method: 'gethello', controller: 'appcontroller', trace: 'tracing....' }
}
);
Publish
For contributors, you need to have an npm account. Follow the steps below to publish:
npm login
npm publish
0.0.1
4 months ago