ConsoleJanitor: Ignore all loggers with whitelist (#2896)
This commit is contained in:
parent
eaf62d8c1c
commit
e4318a887a
|
@ -1,5 +1,5 @@
|
||||||
# ConsoleJanitor
|
# ConsoleJanitor
|
||||||
|
|
||||||
Disables annoying console messages/errors. This plugin mainly removes errors/warnings that happen all the time and noisy/spammy logging messages.
|
Disables annoying console messages/errors. This plugin mainly removes errors/warnings that happen all the time and Discord logger messages.
|
||||||
|
|
||||||
Some of the disabled messages include the "notosans-400-normalitalic" error and MessageActionCreators, Routing/Utils loggers.
|
One of the disabled messages is the "Window state not initialized" warning, for example.
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType, StartAt } from "@utils/types";
|
||||||
|
|
||||||
const Noop = () => { };
|
const Noop = () => { };
|
||||||
const NoopLogger = {
|
const NoopLogger = {
|
||||||
|
@ -22,10 +22,12 @@ const NoopLogger = {
|
||||||
fileOnly: Noop
|
fileOnly: Noop
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const logAllow = new Set();
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
const settings = definePluginSettings({
|
||||||
disableNoisyLoggers: {
|
disableLoggers: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
description: "Disable noisy loggers like the MessageActionCreators",
|
description: "Disables Discords loggers",
|
||||||
default: false,
|
default: false,
|
||||||
restartNeeded: true
|
restartNeeded: true
|
||||||
},
|
},
|
||||||
|
@ -34,16 +36,34 @@ const settings = definePluginSettings({
|
||||||
description: "Disable the Spotify logger, which leaks account information and access token",
|
description: "Disable the Spotify logger, which leaks account information and access token",
|
||||||
default: true,
|
default: true,
|
||||||
restartNeeded: true
|
restartNeeded: true
|
||||||
|
},
|
||||||
|
whitelistedLoggers: {
|
||||||
|
type: OptionType.STRING,
|
||||||
|
description: "Semi colon separated list of loggers to allow even if others are hidden",
|
||||||
|
default: "GatewaySocket; Routing/Utils",
|
||||||
|
onChange(newVal: string) {
|
||||||
|
logAllow.clear();
|
||||||
|
newVal.split(";").map(x => x.trim()).forEach(logAllow.add.bind(logAllow));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "ConsoleJanitor",
|
name: "ConsoleJanitor",
|
||||||
description: "Disables annoying console messages/errors",
|
description: "Disables annoying console messages/errors",
|
||||||
authors: [Devs.Nuckyz],
|
authors: [Devs.Nuckyz, Devs.sadan],
|
||||||
settings,
|
settings,
|
||||||
|
|
||||||
|
startAt: StartAt.Init,
|
||||||
|
start() {
|
||||||
|
logAllow.clear();
|
||||||
|
this.settings.store.whitelistedLoggers?.split(";").map(x => x.trim()).forEach(logAllow.add.bind(logAllow));
|
||||||
|
},
|
||||||
|
|
||||||
NoopLogger: () => NoopLogger,
|
NoopLogger: () => NoopLogger,
|
||||||
|
shouldLog(logger: string) {
|
||||||
|
return logAllow.has(logger);
|
||||||
|
},
|
||||||
|
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
|
@ -103,34 +123,13 @@ export default definePlugin({
|
||||||
replace: ""
|
replace: ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
...[
|
// Patches discords generic logger function
|
||||||
'("MessageActionCreators")', '("ChannelMessages")',
|
|
||||||
'("Routing/Utils")', '("RTCControlSocket")',
|
|
||||||
'("ConnectionEventFramerateReducer")', '("RTCLatencyTestManager")',
|
|
||||||
'("OverlayBridgeStore")', '("RPCServer:WSS")', '("RPCServer:IPC")'
|
|
||||||
].map(logger => ({
|
|
||||||
find: logger,
|
|
||||||
predicate: () => settings.store.disableNoisyLoggers,
|
|
||||||
all: true,
|
|
||||||
replacement: {
|
|
||||||
match: new RegExp(String.raw`new \i\.\i${logger.replace(/([()])/g, "\\$1")}`),
|
|
||||||
replace: `$self.NoopLogger${logger}`
|
|
||||||
}
|
|
||||||
})),
|
|
||||||
{
|
{
|
||||||
find: '"Experimental codecs: "',
|
find: "Σ:",
|
||||||
predicate: () => settings.store.disableNoisyLoggers,
|
predicate: () => settings.store.disableLoggers,
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /new \i\.\i\("Connection\("\.concat\(\i,"\)"\)\)/,
|
match: /(?<=&&)(?=console)/,
|
||||||
replace: "$self.NoopLogger()"
|
replace: "$self.shouldLog(arguments[0])&&"
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
find: '"_handleLocalVideoDisabled: ',
|
|
||||||
predicate: () => settings.store.disableNoisyLoggers,
|
|
||||||
replacement: {
|
|
||||||
match: /new \i\.\i\("RTCConnection\("\.concat.+?\)\)(?=,)/,
|
|
||||||
replace: "$self.NoopLogger()"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -141,5 +140,5 @@ export default definePlugin({
|
||||||
replace: "$self.NoopLogger()"
|
replace: "$self.NoopLogger()"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue