Browse Source

Merge pull request #1095 from gre/improve-logs

Polishes on logs
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
b91fd6ee69
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/helpers/socket.js
  2. 25
      src/logger/logger.js

8
src/helpers/socket.js

@ -31,11 +31,11 @@ export const createDeviceSocket = (transport: Transport<*>, url: string) =>
invariant(ws, 'websocket is available') invariant(ws, 'websocket is available')
ws.on('open', () => { ws.on('open', () => {
logger.websocket('OPENED', url) logger.websocket('OPENED', { url })
}) })
ws.on('error', e => { ws.on('error', e => {
logger.websocket('ERROR', e) logger.websocket('ERROR', { message: e.message, stack: e.stack })
o.error(new WebsocketConnectionError(e.message, { url })) o.error(new WebsocketConnectionError(e.message, { url }))
}) })
@ -97,7 +97,7 @@ export const createDeviceSocket = (transport: Transport<*>, url: string) =>
}, },
error: msg => { error: msg => {
logger.websocket('ERROR', msg.data) logger.websocket('ERROR', { data: msg.data })
throw new DeviceSocketFail(msg.data, { url }) throw new DeviceSocketFail(msg.data, { url })
}, },
} }
@ -114,7 +114,7 @@ export const createDeviceSocket = (transport: Transport<*>, url: string) =>
logger.websocket('RECEIVE', msg) logger.websocket('RECEIVE', msg)
await handlers[msg.query](msg) await handlers[msg.query](msg)
} catch (err) { } catch (err) {
logger.websocket('ERROR', err.toString()) logger.websocket('ERROR', { message: err.message, stack: err.stack })
o.error(err) o.error(err)
} }
} }

25
src/logger/logger.js

@ -47,7 +47,7 @@ const queryLogs = (processName: string, date: Date) =>
const options = { const options = {
from: date - 10 * 60 * 1000, from: date - 10 * 60 * 1000,
until: date, until: date,
limit: 500, limit: 2000,
start: 0, start: 0,
order: 'desc', order: 'desc',
} }
@ -117,7 +117,7 @@ if (process.env.NODE_ENV !== 'production' || process.env.DEV_TOOLS) {
} }
const logger = winston.createLogger({ const logger = winston.createLogger({
level: 'info', level: 'debug',
format: combine(pinfo(), timestamp(), json()), format: combine(pinfo(), timestamp(), json()),
transports, transports,
}) })
@ -161,7 +161,6 @@ export default {
switch (type) { switch (type) {
case 'cmd.START': case 'cmd.START':
logger.log( logger.log(
'info',
'info', 'info',
`CMD ${id}.send()`, `CMD ${id}.send()`,
blacklistTooVerboseCommandInput.includes(id) ? { type } : { type, data }, blacklistTooVerboseCommandInput.includes(id) ? { type } : { type, data },
@ -196,7 +195,7 @@ export default {
onDB: (way: 'read' | 'write' | 'clear', name: string) => { onDB: (way: 'read' | 'write' | 'clear', name: string) => {
const msg = `📁 ${way} ${name}` const msg = `📁 ${way} ${name}`
if (logDb) { if (logDb) {
logger.log('info', msg, { type: 'db' }) logger.log('debug', msg, { type: 'db' })
} }
}, },
@ -204,7 +203,7 @@ export default {
onReduxAction: (action: Object) => { onReduxAction: (action: Object) => {
if (logRedux) { if (logRedux) {
logger.log('info', `⚛️ ${action.type}`, { type: 'action' }) logger.log('debug', `⚛️ ${action.type}`, { type: 'action' })
} }
}, },
@ -215,25 +214,25 @@ export default {
const displayEl = `${tagName.toLowerCase()}${classList.length ? ` ${classList.item(0)}` : ''}` const displayEl = `${tagName.toLowerCase()}${classList.length ? ` ${classList.item(0)}` : ''}`
const msg = `⇓ <TAB> - active element ${displayEl}` const msg = `⇓ <TAB> - active element ${displayEl}`
if (logTabkey) { if (logTabkey) {
logger.log('info', msg, { type: 'keydown' }) logger.log('debug', msg, { type: 'keydown' })
} }
}, },
apdu: (log: string) => { apdu: (log: string) => {
if (logApdu) { if (logApdu) {
logger.log('info', log, { type: 'apdu' }) logger.log('debug', log, { type: 'apdu' })
} }
}, },
websocket: (type: string, msg: *) => { websocket: (type: string, obj?: Object) => {
if (logWS) { if (logWS) {
logger.log('info', `~ ${type}:`, msg, { type: 'ws' }) logger.log('debug', `~ ${type}`, { ...obj, type: 'ws' })
} }
}, },
libcore: (level: string, msg: string) => { libcore: (level: string, msg: string) => {
if (logLibcore) { if (logLibcore) {
logger.log('info', `🛠 ${level}: ${msg}`, { type: 'libcore' }) logger.log(level.toLowerCase(), `🛠 ${msg}`, { type: 'libcore' })
} }
}, },
@ -370,7 +369,11 @@ export default {
message: context, message: context,
}) })
} }
logger.log('error', error) // $FlowFixMe
logger.log('error', error.message, {
stack: error.stack,
...error,
})
if (!process.env.STORYBOOK_ENV) { if (!process.env.STORYBOOK_ENV) {
try { try {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {

Loading…
Cancel
Save