Use circular buffer instead of array for logs
This commit is contained in:
parent
379cd3e0ed
commit
e4623e2ad5
4 changed files with 34 additions and 6 deletions
|
@ -387,6 +387,30 @@ Signal Desktop makes use of the following open source projects.
|
||||||
|
|
||||||
License: MIT
|
License: MIT
|
||||||
|
|
||||||
|
## cirbuf
|
||||||
|
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 Jamie Kyle
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
## classnames
|
## classnames
|
||||||
|
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
|
@ -92,6 +92,7 @@
|
||||||
"blob-util": "2.0.2",
|
"blob-util": "2.0.2",
|
||||||
"blueimp-load-image": "5.14.0",
|
"blueimp-load-image": "5.14.0",
|
||||||
"blurhash": "1.1.3",
|
"blurhash": "1.1.3",
|
||||||
|
"cirbuf": "1.0.1",
|
||||||
"classnames": "2.2.5",
|
"classnames": "2.2.5",
|
||||||
"config": "1.28.1",
|
"config": "1.28.1",
|
||||||
"copy-text-to-clipboard": "2.1.0",
|
"copy-text-to-clipboard": "2.1.0",
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { filter, flatten, map, pick, sortBy } from 'lodash';
|
||||||
import readFirstLine from 'firstline';
|
import readFirstLine from 'firstline';
|
||||||
import { read as readLastLines } from 'read-last-lines';
|
import { read as readLastLines } from 'read-last-lines';
|
||||||
import rimraf from 'rimraf';
|
import rimraf from 'rimraf';
|
||||||
|
import { CircularBuffer } from 'cirbuf';
|
||||||
|
|
||||||
import type { LoggerType } from '../types/Logging';
|
import type { LoggerType } from '../types/Logging';
|
||||||
import * as Errors from '../types/errors';
|
import * as Errors from '../types/errors';
|
||||||
|
@ -44,7 +45,7 @@ declare global {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_LOG_LINES = 1000000;
|
const MAX_LOG_LINES = 10_000_000;
|
||||||
|
|
||||||
let globalLogger: undefined | pino.Logger;
|
let globalLogger: undefined | pino.Logger;
|
||||||
let shouldRestart = false;
|
let shouldRestart = false;
|
||||||
|
@ -287,7 +288,7 @@ export async function eliminateOldEntries(
|
||||||
|
|
||||||
// Exported for testing only.
|
// Exported for testing only.
|
||||||
export async function fetchLog(logFile: string): Promise<Array<LogEntryType>> {
|
export async function fetchLog(logFile: string): Promise<Array<LogEntryType>> {
|
||||||
const results = new Array<LogEntryType>();
|
const results = new CircularBuffer<LogEntryType>(MAX_LOG_LINES);
|
||||||
|
|
||||||
const rawStream = createReadStream(logFile);
|
const rawStream = createReadStream(logFile);
|
||||||
const jsonStream = rawStream.pipe(
|
const jsonStream = rawStream.pipe(
|
||||||
|
@ -311,12 +312,9 @@ export async function fetchLog(logFile: string): Promise<Array<LogEntryType>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
results.push(result);
|
results.push(result);
|
||||||
if (results.length > MAX_LOG_LINES) {
|
|
||||||
results.shift();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results.toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exported for testing only.
|
// Exported for testing only.
|
||||||
|
|
|
@ -6606,6 +6606,11 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3:
|
||||||
inherits "^2.0.1"
|
inherits "^2.0.1"
|
||||||
safe-buffer "^5.0.1"
|
safe-buffer "^5.0.1"
|
||||||
|
|
||||||
|
cirbuf@1.0.1:
|
||||||
|
version "1.0.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/cirbuf/-/cirbuf-1.0.1.tgz#8613dcf424fb4be7c0abf1ce1ed3366971a444ff"
|
||||||
|
integrity sha512-uk/k9s7aJiiH+Xwq2dQRhsOZE66eoY4TLca3d7zSv6QUfr4xLCT6xxBm4O4ZRkfF136+E5aVmjTbRrGr76Wilw==
|
||||||
|
|
||||||
class-utils@^0.3.5:
|
class-utils@^0.3.5:
|
||||||
version "0.3.6"
|
version "0.3.6"
|
||||||
resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463"
|
resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463"
|
||||||
|
|
Loading…
Reference in a new issue