Simple opinionated logging module for NodeJs
npm install ultralogSimple opinionated logging module for NodeJs.
Ultralog is a simple and lightweight logging framework for any Node.js application. It provides a common wrapper for logging to various targets, including the console, files, AWS CloudWatch, GCP Stackdriver, and OpenSearch. The library is designed to be modular, allowing you to install only the dependencies you need.
``bash`
npm install ultralog
Here's a simple example of how to use the Logger class:
`typescript
import { Logger } from "ultralog";
// Create a new logger instance
const logger = new Logger("console");
// Log a message
logger.info("Hello, world!");
`
Ultralog supports the following transports:
* console: Logs to the console.file
* : Logs to a file.aws
* : Logs to AWS CloudWatch.gcp
* : Logs to GCP Stackdriver.opensearch
* : Logs to OpenSearch.
You can specify the transport in the Logger constructor:
`typescript
// Use the file transport
const fileLogger = new Logger("file", { filename: "app.log" });
// Use the AWS CloudWatch transport
const awsLogger = new Logger("aws", {
logGroupName: "my-log-group",
logStreamName: "my-log-stream",
region: "us-east-1",
accessKeyId: "YOUR_AWS_ACCESS_KEY_ID",
secretAccessKey: "YOUR_AWS_SECRET_ACCESS_KEY",
});
// Use the OpenSearch transport
const opensearchLogger = new Logger("opensearch", {
node: "http://localhost:9200",
index: "logs",
// Additional OpenSearch configuration options
});
`
To use the aws, gcp, or opensearch transports, you'll need to install some optional dependencies.
To log to AWS CloudWatch, you'll need to install the winston-cloudwatch package:
`bash`
npm install winston-cloudwatch
To log to GCP Stackdriver, you'll need to install the @google-cloud/logging-winston package:
`bash`
npm install @google-cloud/logging-winston
To log to OpenSearch, you'll need to install the winston-opensearch package:
`bash`
npm install winston-opensearch
You can enable verbose logging to include additional information in your log messages, such as the timestamp and log level.
`typescript
const logger = new Logger("console");
// Enable verbose logging
logger.setVerbose(true);
// This will log a more detailed message
logger.info("This is a verbose log message.");
``
Visit
Raise issues at