1.1.0 • Published 6 months ago

gov_auth_logging_lib v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

const express = require('express'); const { DataSource } = require('typeorm'); const { EndpointLogger, LogEntry } = require('express-endpoint-logger');

// Create Express app const app = express();

// Setup database connection const dataSource = new DataSource({ type: "postgres", host: "localhost", port: 5432, username: "your_username", password: "your_password", database: "your_database", entities: LogEntry, synchronize: true // Only use in development! });

// Initialize everything async function startApp() { // Connect to database await dataSource.initialize();

// Create logger instance
const logger = new EndpointLogger({
    dataSource,
    excludePaths: ['/health'], // Optional: paths to not log
    includeMetadata: true      // Optional: include request details
});

// Add logger middleware - this will log all requests
app.use(logger.logActivity());

// Your regular routes
app.get('/api/users', (req, res) => {
    res.json({ users: ['John', 'Jane'] });
});

// Route to view logs
app.get('/logs', async (req, res) => {
    const logs = await logger.getLogs({
        take: 10,  // limit
        skip: 0    // offset
    });
    res.json(logs);
});

// Start server
app.listen(3000, () => {
    console.log('Server running on port 3000');
});

}

startApp().catch(console.error);

1.1.0

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago