Registry / devops / database-logger

database-logger

JSON →
library1.0.4jsnpmunverified

A flexible logging library for Node.js that supports DynamoDB, PostgreSQL, New Relic, or console output. Version 1.0.4 uses a singleton factory pattern with an interface-based design, making it easy to switch backends. Unlike other loggers, it bundles multiple storage options in one package, simplifying configuration. Ships TypeScript types. Release cadence is low (single version).

npm install database-logger
INSTALL
IMPORT
SIG · DATABASE-LOGGER
D
database-logger
devopsjavascriptv1.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DynamoLogger
import { DynamoLogger } from 'database-logger'
const DynamoLogger = require('database-logger').DynamoLogger
ESM-only package; named import. CommonJS destructuring works, but import is preferred.
PostgresLogger
import { PostgresLogger } from 'database-logger'
ESM named export for PostgreSQL logger.
DatabaseLogger
import { DatabaseLogger } from 'database-logger'
Factory class using async singleton pattern. Do not use new, call getInstance.
Logger
import { type Logger } from 'database-logger'
import { LoggerInterface } from 'database-logger'
Type import for the Logger interface, not a class. Wrong pattern: misnamed interface.

Shows how to instantiate and use DynamoLogger, then log/error with metadata. Comments show transition to PostgresLogger.

import { DynamoLogger } from 'database-logger'; const logger = new DynamoLogger({ tableName: 'logs', service: 'my-service', awsConfig: { region: 'us-east-1', accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? '', secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? '', }, }); await logger.log('Server started', { port: 3000 }); await logger.error('Unhandled exception', { error: 'Something broke' }); // Switch to PostgreSQL easily: // import { PostgresLogger } from 'database-logger'; // const pgLogger = new PostgresLogger({ // connectionString: process.env.DATABASE_URL ?? '', // service: 'my-service', // });
Debug
Known issues
gotchaDatabaseLogger.getInstance is async and uses await; forgetting await returns a Promise, not a logger instance.
fix
Use const logger = await DatabaseLogger.getInstance(...);
affects: >=1.0.0
gotchaNew Relic logger requires the newrelic npm package to be installed separately; it is not a bundled dependency.
fix
Run npm install newrelic before using New Relic config.
affects: >=1.0.0
gotchaDynamoLogger expects a table named 'logs' with a specific schema; mismatched table structure will cause write failures.
fix
Create a DynamoDB table with columns: id (String, partition key), level, message, info (Map), service, created_at (Number), ttl (Number).
affects: >=1.0.0
breakingNo breaking changes reported in version 1.0.4; first stable release. All APIs are experimental.
fix
No fix needed.
affects: =1.0.4
Errors
Common errors & fixes
Class constructor DynamoLogger cannot be invoked without 'new'
DynamoLogger is a class and must be instantiated with new keyword.
fix
const logger = new DynamoLogger({...});
TypeError: Cannot read properties of undefined (reading 'log')
Using DatabaseLogger.getInstance without await returns a Promise, not the instance.
fix
const logger = await DatabaseLogger.getInstance({...});
Error: Cannot find module 'newrelic'
New Relic logger attempts to require('newrelic') which is not installed.
fix
npm install newrelic
Error: DynamoDB table 'logs' does not exist
DynamoLogger uses a hardcoded table name; create the table in AWS.
fix
Create DynamoDB table named 'logs' with id (String) as partition key. Ensure correct region/permissions.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
aws-sdkoptionalDynamoDB logger requires AWS SDK v2 for DynamoDB client
pgoptionalPostgreSQL logger requires pg for database connection
newrelicoptionalNew Relic logger requires the New Relic APM agent
Agent activity
4 hits · last 30 days
node
4
Resources
database-logger — npm install database-logger · libregistry