Browse Source

Polish: hide address from urls

master
Gaëtan Renaudeau 7 years ago
parent
commit
9c370aeea6
  1. 4
      src/helpers/db.js
  2. 29
      src/logger.js

4
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
},

29
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/<HIDDEN>')
}
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)
}

Loading…
Cancel
Save