From 116eceaac461c6b646dabf7437fb16400c34300c Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 22 Feb 2023 15:47:19 +0100 Subject: [PATCH] Remove migration of alpha-10 single file logs This code is no longer functional after the master/slave rename and has served its purpose to migrate the exsting logs to the new format. --- packages/controller/controller.js | 22 ------------ packages/host/host.js | 14 -------- packages/lib/logging_utils.js | 57 ------------------------------- 3 files changed, 93 deletions(-) diff --git a/packages/controller/controller.js b/packages/controller/controller.js index 0812196f..84397d48 100755 --- a/packages/controller/controller.js +++ b/packages/controller/controller.js @@ -237,28 +237,6 @@ async function initialize() { .argv ; - { - // Migration from alpha-10 single file logs, note that we can't use - // the logger here as it's not initalized yet. - /* eslint-disable no-console */ - let clusterLogDirectory = path.join(parameters.args.logDirectory, "cluster"); - if (!await fs.pathExists(clusterLogDirectory) && await fs.pathExists("cluster.log")) { - console.log("Migrating cluster log..."); - await fs.ensureDir(clusterLogDirectory); - await libLoggingUtils.migrateLogs("cluster.log", clusterLogDirectory, "cluster-%DATE%.log"); - console.log("Migration complete, you should delete cluster.log now"); - } - - let controllerLogDirectory = path.join(parameters.args.logDirectory, "controller"); - if (!await fs.pathExists(controllerLogDirectory) && await fs.pathExists("controller.log")) { - console.log("Migrating controller log..."); - await fs.ensureDir(controllerLogDirectory); - await libLoggingUtils.migrateLogs("controller.log", controllerLogDirectory, "controller-%DATE%.log"); - console.log("Migration complete, you should delete controller.log now"); - } - /* eslint-enable no-console */ - } - // Combined log stream of the whole cluster. parameters.clusterLogger = winston.createLogger({ format: winston.format.json(), diff --git a/packages/host/host.js b/packages/host/host.js index fae49687..9ae809ea 100755 --- a/packages/host/host.js +++ b/packages/host/host.js @@ -102,20 +102,6 @@ async function startHost() { .argv ; - { - // Migration from alpha-10 single file logs, note that we can't use - // the logger here as it's not initalized yet. - /* eslint-disable no-console */ - let hostLogDirectory = path.join(args.logDirectory, "host"); - if (!await fs.pathExists(hostLogDirectory) && await fs.pathExists("host.log")) { - console.log("Migrating host log..."); - await fs.ensureDir(hostLogDirectory); - await libLoggingUtils.migrateLogs("host.log", hostLogDirectory, "host-%DATE%.log"); - console.log("Migration complete, you should delete host.log now"); - } - /* eslint-enable no-console */ - } - logger.add(new winston.transports.DailyRotateFile({ format: winston.format.json(), filename: "host-%DATE%.log", diff --git a/packages/lib/logging_utils.js b/packages/lib/logging_utils.js index 218abada..668e6d8a 100644 --- a/packages/lib/logging_utils.js +++ b/packages/lib/logging_utils.js @@ -402,62 +402,6 @@ async function queryLog(logDirectory, filter, index) { return log; } -async function migrateLogs(log, directory, pattern) { - const dateRegExp = /^\d{4}-\d{2}-\d{2}/; - let lineStream = new libStream.LineSplitter({ readableObjectMode: true }); - let fileStream = fs.createReadStream(log); - fileStream.pipe(lineStream); - - let currentDate = null; - let output = null; - - async function switchOutput(newOutputPath) { - if (output) { - output.end(); - await finished(output); - } - - output = fs.createWriteStream(newOutputPath, { flags: "ax" }); - try { - await events.once(output, "open"); - // eslint-disable-next-line no-console - console.log(`writing ${newOutputPath}`); - } catch (err) { - if (err.code === "EEXIST") { - // eslint-disable-next-line no-console - console.warn(`Discarding logs for ${newDate} due to target logfile already existing`); - output = null; - } else { - throw err; - } - } - } - - for await (let line of lineStream) { - let info = {}; - try { - info = JSON.parse(line); - } catch (err) { - // Ignore - } - - if (typeof info.timestamp === "string" && dateRegExp.test(info.timestamp)) { - let newDate = info.timestamp.slice(0, 10); - // Only update date forward in time. - if (newDate !== currentDate && (!currentDate || newDate > currentDate)) { - await switchOutput(path.join(directory, pattern.replace("%DATE%", newDate))); - currentDate = newDate; - } - } - - if (output) { - if (!output.write(Buffer.concat([line, Buffer.from("\n")]))) { - await events.once(output, "drain"); - } - } - } -} - function handleUnhandledErrors() { /* eslint-disable node/no-process-exit */ process.on("uncaughtException", err => { @@ -478,7 +422,6 @@ module.exports = { LogIndex, handleUnhandledErrors, queryLog, - migrateLogs, // for testing only _formatServerOutput: formatServerOutput,