diff --git a/config/default.yaml b/config/default.yaml index 8a2b2958..f31f1ee0 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -74,10 +74,6 @@ verboseLogging: false # This should be at INFO or DEBUG in order to get support for Draupnir problems. logLevel: "INFO" -# Whether or not Draupnir should synchronize policy lists immediately after startup. -# Equivalent to running '!draupnir sync'. -syncOnStartup: true - # Whether or not Draupnir should check moderation permissions in all protected rooms on startup. # Equivalent to running `!draupnir verify`. verifyPermissionsOnStartup: true diff --git a/config/harness.yaml b/config/harness.yaml index 2d488352..beb2fc32 100644 --- a/config/harness.yaml +++ b/config/harness.yaml @@ -57,10 +57,6 @@ verboseLogging: false # This should be at INFO or DEBUG in order to get support for Mjolnir problems. logLevel: "DEBUG" -# Set to false to disable synchronizing the ban lists on startup. If true, this -# is the same as running !mjolnir sync immediately after startup. -syncOnStartup: true - # Set to false to prevent Mjolnir from checking its permissions on startup. This # is recommended to be left as "true" to catch room permission problems (state # resets, etc) before Mjolnir is needed. diff --git a/src/config.ts b/src/config.ts index f566aa44..8e47fae0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -70,10 +70,8 @@ export interface IConfig { acceptInvitesFromSpace: string | undefined; recordIgnoredInvites: boolean; managementRoom: string; - verboseLogging: boolean; logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR"; logMutedModules: string[]; - syncOnStartup: boolean; verifyPermissionsOnStartup: boolean; disableServerACL: boolean; noop: boolean; @@ -188,10 +186,8 @@ const defaultConfig: IConfig = { autojoinOnlyIfManager: true, recordIgnoredInvites: false, managementRoom: "!noop:example.org", - verboseLogging: false, logLevel: "INFO", logMutedModules: ["MatrixHttpClient", "MatrixClientLite"], - syncOnStartup: true, verifyPermissionsOnStartup: true, noop: false, disableServerACL: false, @@ -373,9 +369,7 @@ export function getProvisionedMjolnirConfig(managementRoomId: string): IConfig { // on every created Draupnir, which would result in very confusing error messages. const allowedKeys = [ "commands", - "verboseLogging", "logLevel", - "syncOnStartup", "verifyPermissionsOnStartup", "automaticallyRedactForReasons", "protectAllJoinedRooms", diff --git a/src/managementroom/ManagementRoomOutput.ts b/src/managementroom/ManagementRoomOutput.ts index e6244de3..79c64cc9 100644 --- a/src/managementroom/ManagementRoomOutput.ts +++ b/src/managementroom/ManagementRoomOutput.ts @@ -41,7 +41,7 @@ export interface ManagementRoomOutput { managementRoomID: StringRoomID; /** * Log a message to the management room and the console, replaces any room ids in additionalRoomIds with pills. - * @param level Used to determine whether to hide the message or not depending on `config.verboseLogging`. + * @param level Used to determine whether to hide the message or not depending on `config.logLevel`. * @param module Used to help find where in the source the message is coming from (when logging to the console). * @param message The message we want to log. * @param additionalRoomIds The roomIds in the message that we want to be replaced by room pills. @@ -173,7 +173,8 @@ export default class StandardManagementRoomOutput if (!Array.isArray(additionalRoomIds)) additionalRoomIds = [additionalRoomIds]; - if (this.config.verboseLogging || LogLevel.INFO.includes(level)) { + const levelsIncluded = LogLevel[this.config.logLevel]; + if (levelsIncluded.includes(level)) { let clientMessage = message; if (level === LogLevel.WARN) clientMessage = `⚠ | ${message}`; if (level === LogLevel.ERROR) clientMessage = `‼ | ${message}`; diff --git a/src/utils.ts b/src/utils.ts index 4c1cba78..9d79e3e8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -18,12 +18,13 @@ import { } from "matrix-bot-sdk"; import { ClientRequest, IncomingMessage } from "http"; import * as Sentry from "@sentry/node"; - import ManagementRoomOutput from "./managementroom/ManagementRoomOutput"; import { IConfig } from "./config"; import { Gauge } from "prom-client"; import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk"; -import { RoomEvent } from "matrix-protection-suite"; +import { Logger, RoomEvent } from "matrix-protection-suite"; + +const log = new Logger("utils"); export function htmlEscape(input: string): string { // eslint-disable-next-line @typescript-eslint/restrict-plus-operands @@ -103,9 +104,7 @@ export async function redactUserMessagesIn( noop = false ) { for (const targetRoomId of targetRoomIds) { - await managementRoom.logMessage( - LogLevel.DEBUG, - "utils#redactUserMessagesIn", + log.debug( `Fetching sent messages for ${userIdOrGlob} in ${targetRoomId} to redact...`, targetRoomId ); @@ -118,9 +117,7 @@ export async function redactUserMessagesIn( limit, async (eventsToRedact) => { for (const victimEvent of eventsToRedact) { - await managementRoom.logMessage( - LogLevel.DEBUG, - "utils#redactUserMessagesIn", + log.debug( `Redacting ${victimEvent["event_id"]} in ${targetRoomId}`, targetRoomId ); @@ -128,8 +125,7 @@ export async function redactUserMessagesIn( await client .redactEvent(targetRoomId, victimEvent["event_id"]) .catch((error: unknown) => { - LogService.error( - "utils#redactUserMessagesIn", + log.error( `Error while trying to redact messages for ${userIdOrGlob} in ${targetRoomId}:`, error, targetRoomId