Removes trailing spaces.
This commit is contained in:
parent
a190311612
commit
eaa4c3cf0b
@ -10,7 +10,7 @@ import lockfile from "proper-lockfile";
|
|||||||
import { IAsyncQueue } from "@spt-aki/models/spt/utils/IAsyncQueue";
|
import { IAsyncQueue } from "@spt-aki/models/spt/utils/IAsyncQueue";
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class VFS
|
export class VFS
|
||||||
{
|
{
|
||||||
accessFilePromisify: (path: fs.PathLike, mode?: number) => Promise<void>;
|
accessFilePromisify: (path: fs.PathLike, mode?: number) => Promise<void>;
|
||||||
copyFilePromisify: (src: fs.PathLike, dst: fs.PathLike, flags?: number) => Promise<void>;
|
copyFilePromisify: (src: fs.PathLike, dst: fs.PathLike, flags?: number) => Promise<void>;
|
||||||
@ -39,14 +39,14 @@ export class VFS
|
|||||||
this.renamePromisify = promisify(fs.renameSync);
|
this.renamePromisify = promisify(fs.renameSync);
|
||||||
}
|
}
|
||||||
|
|
||||||
public exists(filepath: fs.PathLike): boolean
|
public exists(filepath: fs.PathLike): boolean
|
||||||
{
|
{
|
||||||
return fs.existsSync(filepath);
|
return fs.existsSync(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async existsAsync(filepath: fs.PathLike): Promise<boolean>
|
public async existsAsync(filepath: fs.PathLike): Promise<boolean>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Create the command to add to the queue
|
// Create the command to add to the queue
|
||||||
const command = {
|
const command = {
|
||||||
@ -59,19 +59,19 @@ export class VFS
|
|||||||
// If no Exception, the file exists
|
// If no Exception, the file exists
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// If Exception, the file does not exis
|
// If Exception, the file does not exist
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public copyFile(filepath: fs.PathLike, target: fs.PathLike): void
|
public copyFile(filepath: fs.PathLike, target: fs.PathLike): void
|
||||||
{
|
{
|
||||||
fs.copyFileSync(filepath, target);
|
fs.copyFileSync(filepath, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async copyAsync(filepath: fs.PathLike, target: fs.PathLike): Promise<void>
|
public async copyAsync(filepath: fs.PathLike, target: fs.PathLike): Promise<void>
|
||||||
{
|
{
|
||||||
const command = {
|
const command = {
|
||||||
uuid: crypto.randomUUID(),
|
uuid: crypto.randomUUID(),
|
||||||
@ -80,12 +80,12 @@ export class VFS
|
|||||||
await this.asyncQueue.waitFor(command);
|
await this.asyncQueue.waitFor(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public createDir(filepath: string): void
|
public createDir(filepath: string): void
|
||||||
{
|
{
|
||||||
fs.mkdirSync(filepath.substr(0, filepath.lastIndexOf("/")), { "recursive": true });
|
fs.mkdirSync(filepath.substr(0, filepath.lastIndexOf("/")), { "recursive": true });
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createDirAsync(filepath: string): Promise<void>
|
public async createDirAsync(filepath: string): Promise<void>
|
||||||
{
|
{
|
||||||
const command = {
|
const command = {
|
||||||
uuid: crypto.randomUUID(),
|
uuid: crypto.randomUUID(),
|
||||||
@ -94,65 +94,65 @@ export class VFS
|
|||||||
await this.asyncQueue.waitFor(command);
|
await this.asyncQueue.waitFor(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public copyDir(filepath: string, target: string, fileExtensions: string | string[] = undefined): void
|
public copyDir(filepath: string, target: string, fileExtensions: string | string[] = undefined): void
|
||||||
{
|
{
|
||||||
const files = this.getFiles(filepath);
|
const files = this.getFiles(filepath);
|
||||||
const dirs = this.getDirs(filepath);
|
const dirs = this.getDirs(filepath);
|
||||||
|
|
||||||
if (!this.exists(target))
|
if (!this.exists(target))
|
||||||
{
|
{
|
||||||
this.createDir(`${target}/`);
|
this.createDir(`${target}/`);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const dir of dirs)
|
for (const dir of dirs)
|
||||||
{
|
{
|
||||||
this.copyDir(path.join(filepath, dir), path.join(target, dir), fileExtensions);
|
this.copyDir(path.join(filepath, dir), path.join(target, dir), fileExtensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const file of files)
|
for (const file of files)
|
||||||
{
|
{
|
||||||
// copy all if fileExtension is not set, copy only those with fileExtension if set
|
// copy all if fileExtension is not set, copy only those with fileExtension if set
|
||||||
if (!fileExtensions || fileExtensions.includes(file.split(".").pop()))
|
if (!fileExtensions || fileExtensions.includes(file.split(".").pop()))
|
||||||
{
|
{
|
||||||
this.copyFile(path.join(filepath, file), path.join(target, file));
|
this.copyFile(path.join(filepath, file), path.join(target, file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async copyDirAsync(filepath: string, target: string, fileExtensions: string | string[]): Promise<void>
|
public async copyDirAsync(filepath: string, target: string, fileExtensions: string | string[]): Promise<void>
|
||||||
{
|
{
|
||||||
const files = this.getFiles(filepath);
|
const files = this.getFiles(filepath);
|
||||||
const dirs = this.getDirs(filepath);
|
const dirs = this.getDirs(filepath);
|
||||||
|
|
||||||
if (!await this.existsAsync(target))
|
if (!await this.existsAsync(target))
|
||||||
{
|
{
|
||||||
await this.createDirAsync(`${target}/`);
|
await this.createDirAsync(`${target}/`);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const dir of dirs)
|
for (const dir of dirs)
|
||||||
{
|
{
|
||||||
await this.copyDirAsync(path.join(filepath, dir), path.join(target, dir), fileExtensions);
|
await this.copyDirAsync(path.join(filepath, dir), path.join(target, dir), fileExtensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const file of files)
|
for (const file of files)
|
||||||
{
|
{
|
||||||
// copy all if fileExtension is not set, copy only those with fileExtension if set
|
// copy all if fileExtension is not set, copy only those with fileExtension if set
|
||||||
if (!fileExtensions || fileExtensions.includes(file.split(".").pop()))
|
if (!fileExtensions || fileExtensions.includes(file.split(".").pop()))
|
||||||
{
|
{
|
||||||
await this.copyAsync(path.join(filepath, file), path.join(target, file));
|
await this.copyAsync(path.join(filepath, file), path.join(target, file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public readFile(...args: Parameters<typeof fs.readFileSync>): string
|
public readFile(...args: Parameters<typeof fs.readFileSync>): string
|
||||||
{
|
{
|
||||||
const read = fs.readFileSync(...args);
|
const read = fs.readFileSync(...args);
|
||||||
if (this.isBuffer(read))
|
if (this.isBuffer(read))
|
||||||
return read.toString();
|
return read.toString();
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async readFileAsync(path: fs.PathLike): Promise<string>
|
public async readFileAsync(path: fs.PathLike): Promise<string>
|
||||||
{
|
{
|
||||||
const read = await this.readFilePromisify(path);
|
const read = await this.readFilePromisify(path);
|
||||||
if (this.isBuffer(read))
|
if (this.isBuffer(read))
|
||||||
@ -165,11 +165,11 @@ export class VFS
|
|||||||
return value?.write && value.toString && value.toJSON && value.equals;
|
return value?.write && value.toString && value.toJSON && value.equals;
|
||||||
}
|
}
|
||||||
|
|
||||||
public writeFile(filepath: any, data = "", append = false, atomic = true): void
|
public writeFile(filepath: any, data = "", append = false, atomic = true): void
|
||||||
{
|
{
|
||||||
const options = (append) ? { "flag": "a" } : { "flag": "w" };
|
const options = (append) ? { "flag": "a" } : { "flag": "w" };
|
||||||
|
|
||||||
if (!this.exists(filepath))
|
if (!this.exists(filepath))
|
||||||
{
|
{
|
||||||
this.createDir(filepath);
|
this.createDir(filepath);
|
||||||
fs.writeFileSync(filepath, "");
|
fs.writeFileSync(filepath, "");
|
||||||
@ -177,53 +177,53 @@ export class VFS
|
|||||||
|
|
||||||
this.lockFileSync(filepath);
|
this.lockFileSync(filepath);
|
||||||
|
|
||||||
if (!append && atomic)
|
if (!append && atomic)
|
||||||
{
|
{
|
||||||
writeFileSync(filepath, data);
|
writeFileSync(filepath, data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fs.writeFileSync(filepath, data, options);
|
fs.writeFileSync(filepath, data, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.checkFileSync(filepath))
|
if (this.checkFileSync(filepath))
|
||||||
{
|
{
|
||||||
this.unlockFileSync(filepath);
|
this.unlockFileSync(filepath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async writeFileAsync(filepath: any, data = "", append = false, atomic = true): Promise<void>
|
public async writeFileAsync(filepath: any, data = "", append = false, atomic = true): Promise<void>
|
||||||
{
|
{
|
||||||
const options = (append) ? { "flag": "a" } : { "flag": "w" };
|
const options = (append) ? { "flag": "a" } : { "flag": "w" };
|
||||||
|
|
||||||
if (!await this.exists(filepath))
|
if (!await this.exists(filepath))
|
||||||
{
|
{
|
||||||
await this.createDir(filepath);
|
await this.createDir(filepath);
|
||||||
await this.writeFilePromisify(filepath, "");
|
await this.writeFilePromisify(filepath, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!append && atomic)
|
if (!append && atomic)
|
||||||
{
|
{
|
||||||
await this.writeFilePromisify(filepath, data);
|
await this.writeFilePromisify(filepath, data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await this.writeFilePromisify(filepath, data, options);
|
await this.writeFilePromisify(filepath, data, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getFiles(filepath: string): string[]
|
public getFiles(filepath: string): string[]
|
||||||
{
|
{
|
||||||
return fs.readdirSync(filepath).filter((item) =>
|
return fs.readdirSync(filepath).filter((item) =>
|
||||||
{
|
{
|
||||||
return fs.statSync(path.join(filepath, item)).isFile();
|
return fs.statSync(path.join(filepath, item)).isFile();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getFilesAsync(filepath: string): Promise<string[]>
|
public async getFilesAsync(filepath: string): Promise<string[]>
|
||||||
{
|
{
|
||||||
const addr = await this.readdirPromisify(filepath);
|
const addr = await this.readdirPromisify(filepath);
|
||||||
return addr.filter(async (item) =>
|
return addr.filter(async (item) =>
|
||||||
{
|
{
|
||||||
const stat = await this.statPromisify(path.join(filepath, item));
|
const stat = await this.statPromisify(path.join(filepath, item));
|
||||||
return stat.isFile();
|
return stat.isFile();
|
||||||
@ -231,45 +231,45 @@ export class VFS
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public getDirs(filepath: string): string[]
|
public getDirs(filepath: string): string[]
|
||||||
{
|
{
|
||||||
return fs.readdirSync(filepath).filter((item) =>
|
return fs.readdirSync(filepath).filter((item) =>
|
||||||
{
|
{
|
||||||
return fs.statSync(path.join(filepath, item)).isDirectory();
|
return fs.statSync(path.join(filepath, item)).isDirectory();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getDirsAsync(filepath: string): Promise<string[]>
|
public async getDirsAsync(filepath: string): Promise<string[]>
|
||||||
{
|
{
|
||||||
const addr = await this.readdirPromisify(filepath);
|
const addr = await this.readdirPromisify(filepath);
|
||||||
return addr.filter(async (item) =>
|
return addr.filter(async (item) =>
|
||||||
{
|
{
|
||||||
const stat = await this.statPromisify(path.join(filepath, item));
|
const stat = await this.statPromisify(path.join(filepath, item));
|
||||||
return stat.isDirectory();
|
return stat.isDirectory();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeFile(filepath: string): void
|
public removeFile(filepath: string): void
|
||||||
{
|
{
|
||||||
fs.unlinkSync(filepath);
|
fs.unlinkSync(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async removeFileAsync(filepath: string): Promise<void>
|
public async removeFileAsync(filepath: string): Promise<void>
|
||||||
{
|
{
|
||||||
await this.unlinkPromisify(filepath);
|
await this.unlinkPromisify(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeDir(filepath: string): void
|
public removeDir(filepath: string): void
|
||||||
{
|
{
|
||||||
const files = this.getFiles(filepath);
|
const files = this.getFiles(filepath);
|
||||||
const dirs = this.getDirs(filepath);
|
const dirs = this.getDirs(filepath);
|
||||||
|
|
||||||
for (const dir of dirs)
|
for (const dir of dirs)
|
||||||
{
|
{
|
||||||
this.removeDir(path.join(filepath, dir));
|
this.removeDir(path.join(filepath, dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const file of files)
|
for (const file of files)
|
||||||
{
|
{
|
||||||
this.removeFile(path.join(filepath, file));
|
this.removeFile(path.join(filepath, file));
|
||||||
}
|
}
|
||||||
@ -277,19 +277,19 @@ export class VFS
|
|||||||
fs.rmdirSync(filepath);
|
fs.rmdirSync(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async removeDirAsync(filepath: string): Promise<void>
|
public async removeDirAsync(filepath: string): Promise<void>
|
||||||
{
|
{
|
||||||
const files = this.getFiles(filepath);
|
const files = this.getFiles(filepath);
|
||||||
const dirs = this.getDirs(filepath);
|
const dirs = this.getDirs(filepath);
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
for (const dir of dirs)
|
for (const dir of dirs)
|
||||||
{
|
{
|
||||||
promises.push(this.removeDirAsync(path.join(filepath, dir)));
|
promises.push(this.removeDirAsync(path.join(filepath, dir)));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const file of files)
|
for (const file of files)
|
||||||
{
|
{
|
||||||
promises.push(this.removeFile(path.join(filepath, file)));
|
promises.push(this.removeFile(path.join(filepath, file)));
|
||||||
}
|
}
|
||||||
@ -298,45 +298,45 @@ export class VFS
|
|||||||
await this.rmdirPromisify(filepath);
|
await this.rmdirPromisify(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public rename(oldPath: string, newPath: string): void
|
public rename(oldPath: string, newPath: string): void
|
||||||
{
|
{
|
||||||
fs.renameSync(oldPath, newPath);
|
fs.renameSync(oldPath, newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async renameAsync(oldPath: string, newPath: string): Promise<void>
|
public async renameAsync(oldPath: string, newPath: string): Promise<void>
|
||||||
{
|
{
|
||||||
await this.renamePromisify(oldPath, newPath);
|
await this.renamePromisify(oldPath, newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected lockFileSync(filepath: any): void
|
protected lockFileSync(filepath: any): void
|
||||||
{
|
{
|
||||||
lockfile.lockSync(filepath);
|
lockfile.lockSync(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected checkFileSync(filepath: any): any
|
protected checkFileSync(filepath: any): any
|
||||||
{
|
{
|
||||||
return lockfile.checkSync(filepath);
|
return lockfile.checkSync(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected unlockFileSync(filepath: any): void
|
protected unlockFileSync(filepath: any): void
|
||||||
{
|
{
|
||||||
lockfile.unlockSync(filepath);
|
lockfile.unlockSync(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getFileExtension(filepath: string): string
|
public getFileExtension(filepath: string): string
|
||||||
{
|
{
|
||||||
return filepath.split(".").pop();
|
return filepath.split(".").pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public stripExtension(filepath: string): string
|
public stripExtension(filepath: string): string
|
||||||
{
|
{
|
||||||
return filepath.split(".").slice(0, -1).join(".");
|
return filepath.split(".").slice(0, -1).join(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async minifyAllJsonInDirRecursive(filepath: string): Promise<void>
|
public async minifyAllJsonInDirRecursive(filepath: string): Promise<void>
|
||||||
{
|
{
|
||||||
const files = this.getFiles(filepath).filter((item) => this.getFileExtension(item) === "json");
|
const files = this.getFiles(filepath).filter((item) => this.getFileExtension(item) === "json");
|
||||||
for (const file of files)
|
for (const file of files)
|
||||||
{
|
{
|
||||||
const filePathAndName = path.join(filepath, file);
|
const filePathAndName = path.join(filepath, file);
|
||||||
const minified = JSON.stringify(JSON.parse(this.readFile(filePathAndName)));
|
const minified = JSON.stringify(JSON.parse(this.readFile(filePathAndName)));
|
||||||
@ -344,16 +344,16 @@ export class VFS
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dirs = this.getDirs(filepath);
|
const dirs = this.getDirs(filepath);
|
||||||
for (const dir of dirs)
|
for (const dir of dirs)
|
||||||
{
|
{
|
||||||
this.minifyAllJsonInDirRecursive(path.join(filepath, dir));
|
this.minifyAllJsonInDirRecursive(path.join(filepath, dir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async minifyAllJsonInDirRecursiveAsync(filepath: string): Promise<void>
|
public async minifyAllJsonInDirRecursiveAsync(filepath: string): Promise<void>
|
||||||
{
|
{
|
||||||
const files = this.getFiles(filepath).filter((item) => this.getFileExtension(item) === "json");
|
const files = this.getFiles(filepath).filter((item) => this.getFileExtension(item) === "json");
|
||||||
for (const file of files)
|
for (const file of files)
|
||||||
{
|
{
|
||||||
const filePathAndName = path.join(filepath, file);
|
const filePathAndName = path.join(filepath, file);
|
||||||
const minified = JSON.stringify(JSON.parse(await this.readFile(filePathAndName)));
|
const minified = JSON.stringify(JSON.parse(await this.readFile(filePathAndName)));
|
||||||
@ -362,7 +362,7 @@ export class VFS
|
|||||||
|
|
||||||
const dirs = this.getDirs(filepath);
|
const dirs = this.getDirs(filepath);
|
||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
for (const dir of dirs)
|
for (const dir of dirs)
|
||||||
{
|
{
|
||||||
promises.push(this.minifyAllJsonInDirRecursive(path.join(filepath, dir)));
|
promises.push(this.minifyAllJsonInDirRecursive(path.join(filepath, dir)));
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import { IAsyncQueue } from "@spt-aki/models/spt/utils/IAsyncQueue";
|
|||||||
import { ICommand } from "@spt-aki/models/spt/utils/ICommand";
|
import { ICommand } from "@spt-aki/models/spt/utils/ICommand";
|
||||||
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
||||||
|
|
||||||
export abstract class AbstractWinstonLogger implements ILogger
|
export abstract class AbstractWinstonLogger implements ILogger
|
||||||
{
|
{
|
||||||
protected showDebugInConsole = false;
|
protected showDebugInConsole = false;
|
||||||
protected filePath: string;
|
protected filePath: string;
|
||||||
@ -55,7 +55,7 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
this.filePath = `${this.getFilePath()}${this.getFileName()}`;
|
this.filePath = `${this.getFilePath()}${this.getFileName()}`;
|
||||||
this.writeFilePromisify = promisify(fs.writeFile);
|
this.writeFilePromisify = promisify(fs.writeFile);
|
||||||
this.showDebugInConsole = globalThis.G_DEBUG_CONFIGURATION;
|
this.showDebugInConsole = globalThis.G_DEBUG_CONFIGURATION;
|
||||||
if (!fs.existsSync(this.getFilePath()))
|
if (!fs.existsSync(this.getFilePath()))
|
||||||
{
|
{
|
||||||
fs.mkdirSync(this.getFilePath(), { recursive: true });
|
fs.mkdirSync(this.getFilePath(), { recursive: true });
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
level: this.showDebugInConsole ? "debug" : "custom",
|
level: this.showDebugInConsole ? "debug" : "custom",
|
||||||
format: format.combine(
|
format: format.combine(
|
||||||
format.colorize({ all: true, colors: this.logLevels.colors }),
|
format.colorize({ all: true, colors: this.logLevels.colors }),
|
||||||
format.printf(({ message }) =>
|
format.printf(({ message }) =>
|
||||||
{
|
{
|
||||||
return `${message}`;
|
return `${message}`;
|
||||||
})
|
})
|
||||||
@ -91,7 +91,7 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
format.timestamp(),
|
format.timestamp(),
|
||||||
format.align(),
|
format.align(),
|
||||||
format.json(),
|
format.json(),
|
||||||
format.printf(({ timestamp, level, message }) =>
|
format.printf(({ timestamp, level, message }) =>
|
||||||
{
|
{
|
||||||
return `[${timestamp}] ${level}: ${message}`;
|
return `[${timestamp}] ${level}: ${message}`;
|
||||||
})
|
})
|
||||||
@ -108,7 +108,7 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
|
|
||||||
if (this.isLogExceptions())
|
if (this.isLogExceptions())
|
||||||
{
|
{
|
||||||
process.on("uncaughtException", (error) =>
|
process.on("uncaughtException", (error) =>
|
||||||
{
|
{
|
||||||
this.error(`${error.name}: ${error.message}`);
|
this.error(`${error.name}: ${error.message}`);
|
||||||
this.error(error.stack);
|
this.error(error.stack);
|
||||||
@ -123,9 +123,9 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
protected abstract isLogExceptions(): boolean;
|
protected abstract isLogExceptions(): boolean;
|
||||||
|
|
||||||
protected abstract getFilePath(): string;
|
protected abstract getFilePath(): string;
|
||||||
|
|
||||||
protected abstract getFileName(): string;
|
protected abstract getFileName(): string;
|
||||||
|
|
||||||
protected getLogMaxSize(): string
|
protected getLogMaxSize(): string
|
||||||
{
|
{
|
||||||
return "5m";
|
return "5m";
|
||||||
@ -136,7 +136,7 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
return "14d";
|
return "14d";
|
||||||
}
|
}
|
||||||
|
|
||||||
public async writeToLogFile(data: string | Daum): Promise<void>
|
public async writeToLogFile(data: string | Daum): Promise<void>
|
||||||
{
|
{
|
||||||
const command: ICommand = {
|
const command: ICommand = {
|
||||||
uuid: crypto.randomUUID(),
|
uuid: crypto.randomUUID(),
|
||||||
@ -145,7 +145,7 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
await this.asyncQueue.waitFor(command);
|
await this.asyncQueue.waitFor(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async log(data: string | Error | Record<string, unknown>, color: string, backgroundColor = "" ): Promise<void>
|
public async log(data: string | Error | Record<string, unknown>, color: string, backgroundColor = "" ): Promise<void>
|
||||||
{
|
{
|
||||||
const textColor = `${color} ${backgroundColor}`.trimEnd();
|
const textColor = `${color} ${backgroundColor}`.trimEnd();
|
||||||
const tmpLogger = createLogger({
|
const tmpLogger = createLogger({
|
||||||
@ -161,14 +161,14 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
|
|
||||||
let command: ICommand;
|
let command: ICommand;
|
||||||
|
|
||||||
if (typeof (data) === "string")
|
if (typeof (data) === "string")
|
||||||
{
|
{
|
||||||
command = {
|
command = {
|
||||||
uuid: crypto.randomUUID(),
|
uuid: crypto.randomUUID(),
|
||||||
cmd: async () => await tmpLogger.log("custom", data)
|
cmd: async () => await tmpLogger.log("custom", data)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
command = {
|
command = {
|
||||||
uuid: crypto.randomUUID(),
|
uuid: crypto.randomUUID(),
|
||||||
@ -179,7 +179,7 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
await this.asyncQueue.waitFor(command);
|
await this.asyncQueue.waitFor(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async error(data: string | Record<string, unknown>): Promise<void>
|
public async error(data: string | Record<string, unknown>): Promise<void>
|
||||||
{
|
{
|
||||||
const command: ICommand = {
|
const command: ICommand = {
|
||||||
uuid: crypto.randomUUID(),
|
uuid: crypto.randomUUID(),
|
||||||
@ -188,7 +188,7 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
await this.asyncQueue.waitFor(command);
|
await this.asyncQueue.waitFor(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async warning(data: string | Record<string, unknown>): Promise<void>
|
public async warning(data: string | Record<string, unknown>): Promise<void>
|
||||||
{
|
{
|
||||||
const command: ICommand = {
|
const command: ICommand = {
|
||||||
uuid: crypto.randomUUID(),
|
uuid: crypto.randomUUID(),
|
||||||
@ -197,7 +197,7 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
await this.asyncQueue.waitFor(command);
|
await this.asyncQueue.waitFor(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async success(data: string | Record<string, unknown>): Promise<void>
|
public async success(data: string | Record<string, unknown>): Promise<void>
|
||||||
{
|
{
|
||||||
const command: ICommand = {
|
const command: ICommand = {
|
||||||
uuid: crypto.randomUUID(),
|
uuid: crypto.randomUUID(),
|
||||||
@ -206,7 +206,7 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
await this.asyncQueue.waitFor(command);
|
await this.asyncQueue.waitFor(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async info(data: string | Record<string, unknown>): Promise<void>
|
public async info(data: string | Record<string, unknown>): Promise<void>
|
||||||
{
|
{
|
||||||
const command: ICommand = {
|
const command: ICommand = {
|
||||||
uuid: crypto.randomUUID(),
|
uuid: crypto.randomUUID(),
|
||||||
@ -231,18 +231,18 @@ export abstract class AbstractWinstonLogger implements ILogger
|
|||||||
await this.asyncQueue.waitFor(command);
|
await this.asyncQueue.waitFor(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async debug(data: string | Record<string, unknown>, onlyShowInConsole = false): Promise<void>
|
public async debug(data: string | Record<string, unknown>, onlyShowInConsole = false): Promise<void>
|
||||||
{
|
{
|
||||||
let command: ICommand;
|
let command: ICommand;
|
||||||
|
|
||||||
if (onlyShowInConsole)
|
if (onlyShowInConsole)
|
||||||
{
|
{
|
||||||
command = {
|
command = {
|
||||||
uuid: crypto.randomUUID(),
|
uuid: crypto.randomUUID(),
|
||||||
cmd: async () => await this.log(data, this.logLevels.colors.debug)
|
cmd: async () => await this.log(data, this.logLevels.colors.debug)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
command = {
|
command = {
|
||||||
uuid: crypto.randomUUID(),
|
uuid: crypto.randomUUID(),
|
||||||
|
@ -4,9 +4,8 @@ import { IAsyncQueue } from "@spt-aki/models/spt/utils/IAsyncQueue";
|
|||||||
import { AbstractWinstonLogger } from "@spt-aki/utils/logging/AbstractWinstonLogger";
|
import { AbstractWinstonLogger } from "@spt-aki/utils/logging/AbstractWinstonLogger";
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class WinstonMainLogger extends AbstractWinstonLogger
|
export class WinstonMainLogger extends AbstractWinstonLogger
|
||||||
{
|
{
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@inject("AsyncQueue") protected asyncQueue: IAsyncQueue
|
@inject("AsyncQueue") protected asyncQueue: IAsyncQueue
|
||||||
)
|
)
|
||||||
@ -14,27 +13,27 @@ export class WinstonMainLogger extends AbstractWinstonLogger
|
|||||||
super(asyncQueue);
|
super(asyncQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected isLogExceptions(): boolean
|
protected isLogExceptions(): boolean
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected isLogToFile(): boolean
|
protected isLogToFile(): boolean
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected isLogToConsole(): boolean
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getFilePath(): string
|
protected isLogToConsole(): boolean
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getFilePath(): string
|
||||||
{
|
{
|
||||||
return "./user/logs/";
|
return "./user/logs/";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getFileName(): string
|
protected getFileName(): string
|
||||||
{
|
{
|
||||||
return "server-%DATE%.log";
|
return "server-%DATE%.log";
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import { IAsyncQueue } from "@spt-aki/models/spt/utils/IAsyncQueue";
|
|||||||
import { AbstractWinstonLogger } from "@spt-aki/utils/logging/AbstractWinstonLogger";
|
import { AbstractWinstonLogger } from "@spt-aki/utils/logging/AbstractWinstonLogger";
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class WinstonRequestLogger extends AbstractWinstonLogger
|
export class WinstonRequestLogger extends AbstractWinstonLogger
|
||||||
{
|
{
|
||||||
constructor(
|
constructor(
|
||||||
@inject("AsyncQueue") protected asyncQueue: IAsyncQueue
|
@inject("AsyncQueue") protected asyncQueue: IAsyncQueue
|
||||||
@ -13,27 +13,27 @@ export class WinstonRequestLogger extends AbstractWinstonLogger
|
|||||||
super(asyncQueue);
|
super(asyncQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected isLogExceptions(): boolean
|
protected isLogExceptions(): boolean
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected isLogToFile(): boolean
|
protected isLogToFile(): boolean
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected isLogToConsole(): boolean
|
protected isLogToConsole(): boolean
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getFilePath(): string
|
protected getFilePath(): string
|
||||||
{
|
{
|
||||||
return "./user/logs/requests/";
|
return "./user/logs/requests/";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getFileName(): string
|
protected getFileName(): string
|
||||||
{
|
{
|
||||||
return "requests-%DATE%.log";
|
return "requests-%DATE%.log";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user