Browse Source

Fix 'Export Logs' to work after more than 10Mb of logs

master
Gaëtan Renaudeau 7 years ago
parent
commit
9f03aa4c51
  1. 3
      src/components/ExportLogsBtn.js
  2. 21
      src/logger/logger.js

3
src/components/ExportLogsBtn.js

@ -33,6 +33,7 @@ class ExportLogsBtn extends Component<{
environment: __DEV__ ? 'development' : 'production', environment: __DEV__ ? 'development' : 'production',
userAgent: window.navigator.userAgent, userAgent: window.navigator.userAgent,
}) })
const date = new Date() // we don't want all the logs that happen after the Export was pressed ^^
const path = remote.dialog.showSaveDialog({ const path = remote.dialog.showSaveDialog({
title: 'Export logs', title: 'Export logs',
defaultPath: `ledgerlive-export-${moment().format( defaultPath: `ledgerlive-export-${moment().format(
@ -46,7 +47,7 @@ class ExportLogsBtn extends Component<{
], ],
}) })
if (path) { if (path) {
const logs = await logger.queryAllLogs() const logs = await logger.queryAllLogs(date)
const json = JSON.stringify(logs) const json = JSON.stringify(logs)
await writeToFile(path, json) await writeToFile(path, json)
} }

21
src/logger/logger.js

@ -32,23 +32,22 @@ function createDailyRotateFile(processName) {
return new winston.transports.DailyRotateFile({ return new winston.transports.DailyRotateFile({
dirname: resolveLogsDirectory(), dirname: resolveLogsDirectory(),
json: true, json: true,
zippedArchive: true,
filename: `ledger-live-${processName}-%DATE%.log`, filename: `ledger-live-${processName}-%DATE%.log`,
datePattern: 'YYYY-MM-DD', datePattern: 'YYYY-MM-DD',
maxSize: '10m', maxSize: '20m',
maxFiles: '14d', maxFiles: '7d',
}) })
} }
const transports = [createDailyRotateFile(pname)] const transports = [createDailyRotateFile(pname)]
const queryLogs = (processName: string) => const queryLogs = (processName: string, date: Date) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const dailyRotateFile = createDailyRotateFile(processName) const dailyRotateFile = createDailyRotateFile(processName)
const options = { const options = {
from: new Date() - 60 * 60 * 1000, from: date - 10 * 60 * 1000,
until: new Date(), until: date,
limit: 100, limit: 500,
start: 0, start: 0,
order: 'desc', order: 'desc',
} }
@ -61,10 +60,10 @@ const queryLogs = (processName: string) =>
}) })
}) })
const queryAllLogs = async () => { const queryAllLogs = async (date: Date = new Date()) => {
const internal = await queryLogs('internal') const internal = await queryLogs('internal', date)
const main = await queryLogs('main') const main = await queryLogs('main', date)
const renderer = await queryLogs('renderer') const renderer = await queryLogs('renderer', date)
const all = internal const all = internal
.concat(main) .concat(main)
.concat(renderer) .concat(renderer)

Loading…
Cancel
Save