Mega push vol 5, working on messaging now
This commit is contained in:
@@ -40,8 +40,8 @@ const RESET = '\x1b[0m';
|
||||
const BOLD = '\x1b[1m';
|
||||
const DIM = '\x1b[2m';
|
||||
|
||||
// Minimum level to output — can be overridden
|
||||
let minLevel: LogLevel = 'debug';
|
||||
// Minimum level to output — debug in dev, info in prod
|
||||
let minLevel: LogLevel = typeof window !== 'undefined' && window.location?.hostname === 'localhost' ? 'debug' : 'info';
|
||||
|
||||
function shouldLog(level: LogLevel): boolean {
|
||||
return LEVEL_PRIORITY[level] >= LEVEL_PRIORITY[minLevel];
|
||||
@@ -80,16 +80,16 @@ function serverLog(entry: LogEntry) {
|
||||
const levelTag = `${color}${BOLD}[${entry.level.toUpperCase()}]${RESET}`;
|
||||
const time = `${DIM}${entry.timestamp}${RESET}`;
|
||||
const ctx = `${color}[${entry.context}]${RESET}`;
|
||||
|
||||
|
||||
let line = `${levelTag} ${time} ${ctx} ${entry.message}`;
|
||||
|
||||
|
||||
if (entry.data !== undefined) {
|
||||
line += `\n ${DIM}data:${RESET} ${formatData(entry.data)}`;
|
||||
}
|
||||
if (entry.error !== undefined) {
|
||||
line += `\n ${color}error:${RESET} ${formatError(entry.error)}`;
|
||||
}
|
||||
|
||||
|
||||
// Use stderr for errors/warnings so they stand out in terminal
|
||||
if (entry.level === 'error') {
|
||||
console.error(line);
|
||||
@@ -103,10 +103,10 @@ function serverLog(entry: LogEntry) {
|
||||
function clientLog(entry: LogEntry) {
|
||||
const prefix = `[${entry.level.toUpperCase()}] [${entry.context}]`;
|
||||
const args: unknown[] = [prefix, entry.message];
|
||||
|
||||
|
||||
if (entry.data !== undefined) args.push(entry.data);
|
||||
if (entry.error !== undefined) args.push(entry.error);
|
||||
|
||||
|
||||
switch (entry.level) {
|
||||
case 'error':
|
||||
console.error(...args);
|
||||
@@ -124,7 +124,7 @@ function clientLog(entry: LogEntry) {
|
||||
|
||||
function log(level: LogLevel, context: string, message: string, extra?: { data?: unknown; error?: unknown }) {
|
||||
if (!shouldLog(level)) return;
|
||||
|
||||
|
||||
const entry: LogEntry = {
|
||||
level,
|
||||
context,
|
||||
@@ -133,19 +133,19 @@ function log(level: LogLevel, context: string, message: string, extra?: { data?:
|
||||
error: extra?.error,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
|
||||
|
||||
if (isServer()) {
|
||||
serverLog(entry);
|
||||
} else {
|
||||
clientLog(entry);
|
||||
}
|
||||
|
||||
|
||||
// Store in recent logs buffer for debugging
|
||||
recentLogs.push(entry);
|
||||
if (recentLogs.length > MAX_RECENT_LOGS) {
|
||||
recentLogs.shift();
|
||||
}
|
||||
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user