Files
onebox/ts/onebox.logging.ts
Juergen Kunz 246a6073e0 Initial commit: Onebox v1.0.0
- Complete Deno-based architecture following nupst/spark patterns
- SQLite database with full schema
- Docker container management
- Service orchestration (Docker + Nginx + DNS + SSL)
- Registry authentication
- Nginx reverse proxy configuration
- Cloudflare DNS integration
- Let's Encrypt SSL automation
- Background daemon with metrics collection
- HTTP API server
- Comprehensive CLI
- Cross-platform compilation setup
- NPM distribution wrapper
- Shell installer script

Core features:
- Deploy containers with single command
- Automatic domain configuration
- Automatic SSL certificates
- Multi-registry support
- Metrics and logging
- Systemd integration

Ready for Angular UI implementation and testing.
2025-10-28 13:05:42 +00:00

125 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Logging utilities for Onebox
*/
type LogLevel = 'info' | 'success' | 'warn' | 'error' | 'debug';
class Logger {
private debugMode = false;
constructor() {
this.debugMode = Deno.args.includes('--debug') || Deno.env.get('DEBUG') === 'true';
}
/**
* Log a message with specified level
*/
log(level: LogLevel, message: string, ...args: unknown[]): void {
const timestamp = new Date().toISOString();
const prefix = this.getPrefix(level);
const formattedMessage = `${prefix} ${message}`;
switch (level) {
case 'error':
console.error(formattedMessage, ...args);
break;
case 'warn':
console.warn(formattedMessage, ...args);
break;
case 'debug':
if (this.debugMode) {
console.log(formattedMessage, ...args);
}
break;
default:
console.log(formattedMessage, ...args);
}
}
/**
* Info level logging
*/
info(message: string, ...args: unknown[]): void {
this.log('info', message, ...args);
}
/**
* Success level logging
*/
success(message: string, ...args: unknown[]): void {
this.log('success', message, ...args);
}
/**
* Warning level logging
*/
warn(message: string, ...args: unknown[]): void {
this.log('warn', message, ...args);
}
/**
* Error level logging
*/
error(message: string, ...args: unknown[]): void {
this.log('error', message, ...args);
}
/**
* Debug level logging (only when --debug flag is present)
*/
debug(message: string, ...args: unknown[]): void {
this.log('debug', message, ...args);
}
/**
* Get colored prefix for log level
*/
private getPrefix(level: LogLevel): string {
const colors = {
info: '\x1b[36m', // Cyan
success: '\x1b[32m', // Green
warn: '\x1b[33m', // Yellow
error: '\x1b[31m', // Red
debug: '\x1b[90m', // Gray
};
const reset = '\x1b[0m';
const icons = {
info: '',
success: '✓',
warn: '⚠',
error: '✖',
debug: '⚙',
};
return `${colors[level]}${icons[level]}${reset}`;
}
/**
* Print a table (simplified version)
*/
table(headers: string[], rows: string[][]): void {
// Calculate column widths
const widths = headers.map((header, i) => {
const maxContentWidth = Math.max(
...rows.map((row) => (row[i] || '').toString().length)
);
return Math.max(header.length, maxContentWidth);
});
// Print header
const headerRow = headers.map((h, i) => h.padEnd(widths[i])).join(' ');
console.log(headerRow);
console.log(headers.map((_, i) => '-'.repeat(widths[i])).join(' '));
// Print rows
for (const row of rows) {
const formattedRow = row.map((cell, i) => (cell || '').toString().padEnd(widths[i])).join(' ');
console.log(formattedRow);
}
}
}
export const logger = new Logger();