@bwisemedia/njs-logger
v0.1.2
Published
Winston-based logger with TCP/HTTP transports (ESM + CJS).
Downloads
25
Readme
@bwisemedia/njs-logger
A Winston-based logger with optional TCP and HTTP transports.
Supports both ESM and CommonJS, and behaves like console.log (multiple arguments).
Features
- ✅ Works in ESM (
import) and CJS (require) - ✅ Multiple arguments like
console.log("a", "b", obj) - ✅ Environment-based configuration (
.env) - ✅ TCP transport (send logs to a remote collector)
- ✅ HTTP transport (send logs to an API endpoint)
- ✅ Pretty print in development, JSON in production
Installation
npm install @bwisemedia/njs-loggerUsage
ESM
import logger from "@bwisemedia/njs-logger";
logger.info("Server started", { port: 3000 });
logger.error("Error:", new Error("Something failed"));CommonJS
const logger = require("@bwisemedia/njs-logger").default;
logger.debug("Debug message", { details: "extra info" });Environment Variables
See .env.example:
| Variable | Default | Description |
| -------------------- | ------------- | -------------------------------- |
| APP_NAME | unknown-app | Application name |
| APP_ENV | development | Environment (dev/prod/test) |
| LOGGER_MIN_LEVEL | info | Log level threshold |
| LOGGER_SEND_TO_ELK | true | Enable/disable remote transports |
| TCP_LOGGER_HOST | 127.0.0.1 | TCP log server host |
| TCP_LOGGER_PORT | 5000 | TCP log server port |
| HTTP_LOGGER_URL | - | HTTP endpoint for logs |
| HTTP_LOGGER_TOKEN | - | Auth token for HTTP logs |
Example with TCP Transport
APP_NAME=my-service \
LOGGER_SEND_TO_ELK=true \
TCP_LOGGER_HOST=logs.internal \
TCP_LOGGER_PORT=9000 \
node app.jsExample with HTTP Transport
APP_NAME=my-service \
LOGGER_SEND_TO_ELK=true \
HTTP_LOGGER_URL=https://logserver/api/logs \
HTTP_LOGGER_TOKEN=abc123 \
node app.jsDevelopment
npm run build
npm linkThen in another project:
npm link @bwisemedia/njs-loggerRelease
Update version:
npm version patchPush with tags:
git push --follow-tagsGitHub Actions will build & publish automatically to npm.
License
MIT
