- Add logger utility (winston-based) - Add apiKeyAuth middleware for API key authentication - Add fieldPermissions middleware for field-level access control - Add Swagger/OpenAPI configuration and integration - Refactor DTOs with Zod validation schemas: - feature-flag.dto.ts - terminal.dto.ts - transaction.dto.ts - ai.dto.ts - Add error classes (AppError, UnauthorizedError, ForbiddenError, etc.) - Add AuthenticatedRequest type for erp-core compatibility - Add ESLint configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
/**
|
|
* Logger Utility
|
|
* Winston-based logging for ERP Mecanicas Diesel
|
|
* Propagated from erp-core
|
|
*/
|
|
import winston from 'winston';
|
|
|
|
const { combine, timestamp, printf, colorize, errors } = winston.format;
|
|
|
|
const logLevel = process.env.LOG_LEVEL || 'info';
|
|
const nodeEnv = process.env.NODE_ENV || 'development';
|
|
|
|
const logFormat = printf(({ level, message, timestamp, ...metadata }) => {
|
|
let msg = `${timestamp} [${level}]: ${message}`;
|
|
if (Object.keys(metadata).length > 0) {
|
|
msg += ` ${JSON.stringify(metadata)}`;
|
|
}
|
|
return msg;
|
|
});
|
|
|
|
export const logger = winston.createLogger({
|
|
level: logLevel,
|
|
format: combine(
|
|
errors({ stack: true }),
|
|
timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
logFormat
|
|
),
|
|
transports: [
|
|
new winston.transports.Console({
|
|
format: combine(
|
|
colorize(),
|
|
timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
logFormat
|
|
),
|
|
}),
|
|
],
|
|
});
|
|
|
|
// Add file transport in production
|
|
if (nodeEnv === 'production') {
|
|
logger.add(
|
|
new winston.transports.File({ filename: 'logs/error.log', level: 'error' })
|
|
);
|
|
logger.add(
|
|
new winston.transports.File({ filename: 'logs/combined.log' })
|
|
);
|
|
}
|