mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
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.
This commit is contained in:
1 parent
6fc3abafd5
commit
116eceaac4
3 files changed
-93
No files matched your search
@@ -237,28 +237,6 @@ async function initialize() {
|
|||||||
.argv
|
.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.
|
// Combined log stream of the whole cluster.
|
||||||
parameters.clusterLogger = winston.createLogger({
|
parameters.clusterLogger = winston.createLogger({
|
||||||
format: winston.format.json(),
|
format: winston.format.json(),
|
||||||
|
|||||||
@@ -102,20 +102,6 @@ async function startHost() {
|
|||||||
.argv
|
.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({
|
logger.add(new winston.transports.DailyRotateFile({
|
||||||
format: winston.format.json(),
|
format: winston.format.json(),
|
||||||
filename: "host-%DATE%.log",
|
filename: "host-%DATE%.log",
|
||||||
|
|||||||
@@ -402,62 +402,6 @@ async function queryLog(logDirectory, filter, index) {
|
|||||||
return log;
|
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() {
|
function handleUnhandledErrors() {
|
||||||
/* eslint-disable node/no-process-exit */
|
/* eslint-disable node/no-process-exit */
|
||||||
process.on("uncaughtException", err => {
|
process.on("uncaughtException", err => {
|
||||||
@@ -478,7 +422,6 @@ module.exports = {
|
|||||||
LogIndex,
|
LogIndex,
|
||||||
handleUnhandledErrors,
|
handleUnhandledErrors,
|
||||||
queryLog,
|
queryLog,
|
||||||
migrateLogs,
|
|
||||||
|
|
||||||
// for testing only
|
// for testing only
|
||||||
_formatServerOutput: formatServerOutput,
|
_formatServerOutput: formatServerOutput,
|
||||||
|
|||||||
Reference in new issue
Block a user