From 9c370aeea61d016ea83e39a42a97f2e20f77561e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 27 Jun 2018 20:18:03 +0200 Subject: [PATCH] Polish: hide address from urls --- src/helpers/db.js | 4 ++-- src/logger.js | 29 ++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/helpers/db.js b/src/helpers/db.js index 3bc2574f..eabeff86 100644 --- a/src/helpers/db.js +++ b/src/helpers/db.js @@ -55,14 +55,14 @@ export default { get: (key: DBKey, defaults: any): any => { const db = store(key) const data = db.get('data', defaults) - logger.onDB('read', key, data) + logger.onDB('read', key) return middleware('get', key, data) }, set: (key: DBKey, val: any) => { const db = store(key) val = middleware('set', key, val) - logger.onDB('write', key, val) + logger.onDB('write', key) db.set('data', val) return val }, diff --git a/src/logger.js b/src/logger.js index f06c8fed..ac2374fe 100644 --- a/src/logger.js +++ b/src/logger.js @@ -24,6 +24,8 @@ const logs = [] const MAX_LOG_LENGTH = 500 const MAX_LOG_JSON_THRESHOLD = 2000 +const anonymousMode = !__DEV__ + function addLog(type, ...args) { logs.push({ type, date: new Date(), args }) if (logs.length > MAX_LOG_LENGTH) { @@ -31,6 +33,11 @@ function addLog(type, ...args) { } } +function anonymizeURL(url) { + if (!anonymousMode) return url + return url.replace(/\/addresses\/[^/]+/g, '/addresses/') +} + const makeSerializableLog = (o: mixed) => { if (typeof o === 'string') return o if (typeof o === 'number') return o @@ -87,10 +94,10 @@ export default { addLog('cmd', type, id, spentTime, data) }, - onDB: (way: 'read' | 'write' | 'clear', name: string, obj: ?Object) => { - const msg = `📁 ${way} ${name}:` + onDB: (way: 'read' | 'write' | 'clear', name: string) => { + const msg = `📁 ${way} ${name}` if (logDb) { - console.log(msg, obj) + console.log(msg) } addLog('db', msg) }, @@ -131,7 +138,7 @@ export default { }, network: ({ method, url }: { method: string, url: string }) => { - const log = `➡📡 ${method} ${url}` + const log = `➡📡 ${method} ${anonymizeURL(url)}` if (logNetwork) { console.log(log) } @@ -149,7 +156,9 @@ export default { status: number, responseTime: number, }) => { - const log = `✔📡 HTTP ${status} ${method} ${url} – finished in ${responseTime.toFixed(0)}ms` + const log = `✔📡 HTTP ${status} ${method} ${anonymizeURL( + url, + )} – finished in ${responseTime.toFixed(0)}ms` if (logNetwork) { console.log(log) } @@ -169,9 +178,9 @@ export default { error: string, responseTime: number, }) => { - const log = `✖📡 HTTP ${status} ${method} ${url} – ${error} – failed after ${responseTime.toFixed( - 0, - )}ms` + const log = `✖📡 HTTP ${status} ${method} ${anonymizeURL( + url, + )} – ${error} – failed after ${responseTime.toFixed(0)}ms` if (logNetwork) { console.log(log) } @@ -187,7 +196,9 @@ export default { url: string, responseTime: number, }) => { - const log = `✖📡 NETWORK DOWN – ${method} ${url} – after ${responseTime.toFixed(0)}ms` + const log = `✖📡 NETWORK DOWN – ${method} ${anonymizeURL(url)} – after ${responseTime.toFixed( + 0, + )}ms` if (logNetwork) { console.log(log) }