Skip to content

Commit

Permalink
Merge pull request #23 from canalplus/fix/log-file-server
Browse files Browse the repository at this point in the history
Fix log-file server option and disable it by default
  • Loading branch information
peaBerberian authored Aug 16, 2024
2 parents 1eeffea + 1959799 commit 9cd5751
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export const DEFAULT_DEVICE_CONNECTION_LIMIT = 500;
export const DEFAULT_INSPECTOR_CONNECTION_LIMIT = 500;
export const DEFAULT_DEVICE_MESSAGE_LIMIT = 1e6;
export const DEFAULT_INSPECTOR_MESSAGE_LIMIT = 1000;
export const DEFAULT_LOG_FILE_PATH = "server_logs.txt";
export const DEFAULT_LOG_FILE_PATH = null;
6 changes: 3 additions & 3 deletions server/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export default new (class Logger {
this._logFile = null;
}

public setLogFile(logFile: string): void {
public setLogFile(logFile: string | null): void {
this._logFile = logFile;
}

public log(...args: unknown[]): void {
console.log(...args);
const logStr = new Date().toISOString() + " - LOG - " + args.join(" ");
if (this._logFile !== null) {
appendFile("server-logs.txt", logStr + "\n", function () {
appendFile(this._logFile, logStr + "\n", function () {
// on finished. Do nothing for now.
});
}
Expand All @@ -25,7 +25,7 @@ export default new (class Logger {
console.warn(...args);
const logStr = new Date().toISOString() + " - WARN - " + args.join(" ");
if (this._logFile !== null) {
appendFile("server-logs.txt", logStr + "\n", function () {
appendFile(this._logFile, logStr + "\n", function () {
// on finished. Do nothing for now.
});
}
Expand Down
5 changes: 2 additions & 3 deletions server/src/option_parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface ParsedOptions {
deviceMessageLimit: number;
inspectorMessageLimit: number;
persistentTokensFile: string | null;
logFile: string;
logFile: string | null;
disableNoToken: boolean;
}

Expand Down Expand Up @@ -173,8 +173,7 @@ const optionsDescription = [
longForm: "log-file",
argumentDescription: "path",
description:
"Path to the server's log file.\n" +
`Defaults to ${DEFAULT_LOG_FILE_PATH}.`,
"If set a log file will be created at this path, containing the server's logs.",
outputVar: "logFile",
},
{
Expand Down

0 comments on commit 9cd5751

Please sign in to comment.