This repository has been archived on 2026-09-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
open-brainy/examples/brainy-service-template/src/utils/logger.js
David Snelling 768acf66ad feat: add zero-configuration Brainy service template with augmentation-first architecture
- Implement WebSocket augmentation for real-time communication
- Implement WebRTC augmentation for peer-to-peer connections
- Implement HTTP augmentation as minimal REST fallback
- Add auto-discovery augmentation for data pattern analysis
- Add adaptive storage augmentation for intelligent resource management
- Add environment adapter augmentation for universal compatibility
- Template auto-detects environment (browser, Node.js, serverless, containers)
- Intelligent transport selection (WebRTC → WebSocket → HTTP)
- Automatic storage optimization (memory → filesystem → S3)
- Zero configuration required - just npm start
- Includes intelligent verb scoring by default
- Works in any environment without configuration
- Full documentation and examples included
2025-08-06 18:17:32 -07:00

63 lines
No EOL
1.7 KiB
JavaScript

import winston from 'winston'
import config from 'config'
const logLevel = config.get('logging.level') || 'info'
const logFormat = config.get('logging.format') || 'combined'
// Create custom format for development
const devFormat = winston.format.combine(
winston.format.timestamp({ format: 'HH:mm:ss' }),
winston.format.colorize(),
winston.format.printf(({ timestamp, level, message, ...meta }) => {
const metaStr = Object.keys(meta).length ? JSON.stringify(meta, null, 2) : ''
return `${timestamp} [${level}]: ${message} ${metaStr}`
})
)
// Create custom format for production
const prodFormat = winston.format.combine(
winston.format.timestamp(),
winston.format.errors({ stack: true }),
winston.format.json()
)
// Create logger instance
export const logger = winston.createLogger({
level: logLevel,
format: logFormat === 'dev' ? devFormat : prodFormat,
defaultMeta: {
service: 'brainy-service',
version: process.env.npm_package_version || '1.0.0'
},
transports: [
new winston.transports.Console({
handleExceptions: true,
handleRejections: true
})
]
})
// Add file logging for production
if (process.env.NODE_ENV === 'production') {
logger.add(new winston.transports.File({
filename: 'logs/error.log',
level: 'error',
handleExceptions: true,
maxsize: 5242880, // 5MB
maxFiles: 5
}))
logger.add(new winston.transports.File({
filename: 'logs/combined.log',
maxsize: 5242880, // 5MB
maxFiles: 5
}))
}
// Capture unhandled errors
logger.exceptions.handle(
new winston.transports.Console(),
new winston.transports.File({ filename: 'logs/exceptions.log' })
)
export default logger