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',
// });
Errors
Common errors & fixes
Class constructor DynamoLogger cannot be invoked without 'new'
DynamoLogger is a class and must be instantiated with new keyword.
fixconst logger = new DynamoLogger({...}); TypeError: Cannot read properties of undefined (reading 'log')
Using DatabaseLogger.getInstance without await returns a Promise, not the instance.
fixconst logger = await DatabaseLogger.getInstance({...}); Error: Cannot find module 'newrelic'
New Relic logger attempts to require('newrelic') which is not installed.
Error: DynamoDB table 'logs' does not exist
DynamoLogger uses a hardcoded table name; create the table in AWS.
fixCreate DynamoDB table named 'logs' with id (String) as partition key. Ensure correct region/permissions.
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