Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename "logs" to "logLines" #1324

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading