droid / logger.js
devme's picture
Upload 12 files
4c71936 verified
raw
history blame
1.15 kB
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 && isDevMode()) {
console.error(error)
}
}
export function logRequest(method, url, headers = null, body = null) {
if (isDevMode()) {
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))
}
}
export function logResponse(status, headers = null, body = null) {
if (isDevMode()) {
console.log(`[RESPONSE] ${status}`)
if (headers) console.log('[HEADERS]', JSON.stringify(headers, null, 2))
if (body) console.log('[BODY]', JSON.stringify(body, null, 2))
}
}