Skip to content

Commit

Permalink
refactor: rename "logs" to "logLines"
Browse files Browse the repository at this point in the history
Make it clear in code storing logs that chunks must be split at
newlines.

Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos committed Feb 9, 2024
1 parent 4eae0e1 commit 190b032
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions main/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Sentry = require('@sentry/node')
const consts = require('./consts')
const { randomUUID } = require('node:crypto')
const { Activities } = require('./activities')
const { Logs } = require('./logs')
const { LogLines } = require('./logs')
const split2 = require('split2')
const { parseEther } = require('ethers/lib/utils')

Expand All @@ -23,7 +23,7 @@ const corePath = app.isPackaged
: join(__dirname, '..', 'core', 'bin', 'station.js')
console.log('Core binary: %s', corePath)

const logs = new Logs()
const logLines = new LogLines()
const activities = new Activities()
let totalJobsCompleted = 0

Expand All @@ -39,7 +39,7 @@ async function setup (ctx) {
ctx.showUI()
const { filePath } = await dialog.showSaveDialog(opts)
if (filePath) {
await fs.writeFile(filePath, logs.get())
await fs.writeFile(filePath, logLines.get())
}
}
await maybeMigrateFiles()
Expand Down Expand Up @@ -68,7 +68,7 @@ async function start (ctx) {
childProcess.stdout
.pipe(split2())
.on('data', line => {
logs.push(line)
logLines.push(line)
let event
try {
event = JSON.parse(line)
Expand Down Expand Up @@ -115,7 +115,7 @@ async function start (ctx) {
childProcess.stderr.setEncoding('utf8')
childProcess.stderr
.pipe(split2())
.on('data', line => logs.push(line))
.on('data', line => logLines.push(line))

/** @type {string | null} */
let exitReason = null
Expand All @@ -130,7 +130,7 @@ async function start (ctx) {
;(async () => {
Sentry.captureException('Core exited', scope => {
// Sentry UI can't show the full 100 lines
scope.setExtra('logs', logs.getLast(10))
scope.setExtra('logs', logLines.getLast(10))
scope.setExtra('reason', exitReason)
return scope
})
Expand Down
12 changes: 6 additions & 6 deletions main/logs.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict'

class Logs {
class LogLines {
/** @type {string[]} */
#logs = []
#logLines = []

/**
* Keep last 100 lines of logs for inspection
* @param {string} line
*/
push (line) {
this.#logs.push(line)
this.#logs.splice(0, this.#logs.length - 100)
this.#logLines.push(line)
this.#logLines.splice(0, this.#logLines.length - 100)
}

get () {
Expand All @@ -22,10 +22,10 @@ class Logs {
* @returns string
*/
getLast (n) {
return this.#logs.slice(-n).join('\n')
return this.#logLines.slice(-n).join('\n')
}
}

module.exports = {
Logs
LogLines
}

0 comments on commit 190b032

Please sign in to comment.