File size: 1,597 Bytes
6dfd5ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import { isDevMode } from './config.js';
export function logInfo(message, data = null) {
console.log(`[INFO] ${message}`);
if (data && isDevMode()) {
console.log(JSON.stringify(data, null, 2));
}
}
export function logDebug(message, data = null) {
if (isDevMode()) {
console.log(`[DEBUG] ${message}`);
if (data) {
console.log(JSON.stringify(data, null, 2));
}
}
}
export function logError(message, error = null) {
console.error(`[ERROR] ${message}`);
if (error) {
if (isDevMode()) {
console.error(error);
} else {
console.error(error.message || error);
}
}
}
export function logRequest(method, url, headers = null, body = null) {
if (isDevMode()) {
console.log(`\n${'='.repeat(80)}`);
console.log(`[REQUEST] ${method} ${url}`);
if (headers) {
console.log('[HEADERS]', JSON.stringify(headers, null, 2));
}
if (body) {
console.log('[BODY]', JSON.stringify(body, null, 2));
}
console.log('='.repeat(80) + '\n');
} else {
console.log(`[REQUEST] ${method} ${url}`);
}
}
export function logResponse(status, headers = null, body = null) {
if (isDevMode()) {
console.log(`\n${'-'.repeat(80)}`);
console.log(`[RESPONSE] Status: ${status}`);
if (headers) {
console.log('[HEADERS]', JSON.stringify(headers, null, 2));
}
if (body) {
console.log('[BODY]', JSON.stringify(body, null, 2));
}
console.log('-'.repeat(80) + '\n');
} else {
console.log(`[RESPONSE] Status: ${status}`);
}
}
|