mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 13:17:08 +00:00
Use matrix-appservice-bridge logging (#488)
* Use matrix-appservice-bridge logger * Update to be in line with bridge sdk * Update packages * changelog * nits
This commit is contained in:
parent
14747bb92e
commit
db3caeae03
1
changelog.d/488.misc
Normal file
1
changelog.d/488.misc
Normal file
@ -0,0 +1 @@
|
||||
Use the `matrix-appservice-bridge` logging implementation.
|
@ -54,8 +54,8 @@
|
||||
"ioredis": "^5.2.3",
|
||||
"jira-client": "^8.0.0",
|
||||
"markdown-it": "^12.3.2",
|
||||
"matrix-appservice-bridge": "^5.0.0",
|
||||
"matrix-bot-sdk": "^0.6.1",
|
||||
"matrix-appservice-bridge": "^6.0.0",
|
||||
"matrix-bot-sdk": "^0.6.2",
|
||||
"matrix-widget-api": "^1.0.0",
|
||||
"micromatch": "^4.0.4",
|
||||
"mime": "^3.0.0",
|
||||
@ -80,7 +80,7 @@
|
||||
"@types/ajv": "^1.0.0",
|
||||
"@types/chai": "^4.2.22",
|
||||
"@types/cors": "^2.8.12",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/express": "^4.17.14",
|
||||
"@types/jira-client": "^7.1.0",
|
||||
"@types/markdown-it": "^12.2.3",
|
||||
"@types/micromatch": "^4.0.1",
|
||||
|
@ -17,13 +17,13 @@ import { JiraBotCommands } from "./Jira/AdminCommands";
|
||||
import { NotifFilter, NotificationFilterStateContent } from "./NotificationFilters";
|
||||
import { ProjectsListResponseData } from "./Github/Types";
|
||||
import { UserTokenStore } from "./UserTokenStore";
|
||||
import LogWrapper from "./LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import markdown from "markdown-it";
|
||||
type ProjectsListForRepoResponseData = Endpoints["GET /repos/{owner}/{repo}/projects"]["response"];
|
||||
type ProjectsListForUserResponseData = Endpoints["GET /users/{username}/projects"]["response"];
|
||||
|
||||
const md = new markdown();
|
||||
const log = new LogWrapper('AdminRoom');
|
||||
const log = new Logger('AdminRoom');
|
||||
|
||||
export const LEGACY_BRIDGE_ROOM_TYPE = "uk.half-shot.matrix-github.room";
|
||||
export const LEGACY_BRIDGE_NOTIF_TYPE = "uk.half-shot.matrix-github.notif_state";
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { Bridge } from "../Bridge";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
|
||||
import { BridgeConfig, parseRegistrationFile } from "../Config/Config";
|
||||
import { Webhooks } from "../Webhooks";
|
||||
import { MatrixSender } from "../MatrixSender";
|
||||
import { UserNotificationWatcher } from "../Notifications/UserNotificationWatcher";
|
||||
import { ListenerService } from "../ListenerService";
|
||||
import { Logging } from "matrix-appservice-bridge";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { LogService } from "matrix-bot-sdk";
|
||||
|
||||
LogWrapper.root.configureLogging({level: "info"});
|
||||
const log = new LogWrapper("App");
|
||||
Logger.configure({console: "info"});
|
||||
const log = new Logger("App");
|
||||
|
||||
async function start() {
|
||||
const configFile = process.argv[2] || "./config.yml";
|
||||
@ -17,10 +17,13 @@ async function start() {
|
||||
const config = await BridgeConfig.parseConfig(configFile, process.env);
|
||||
const registration = await parseRegistrationFile(registrationFile);
|
||||
const listener = new ListenerService(config.listeners);
|
||||
LogWrapper.root.configureLogging(config.logging);
|
||||
// Bridge SDK doesn't support trace, use "debug" instead.
|
||||
const bridgeSdkLevel = config.logging.level === "trace" ? "debug" : config.logging.level;
|
||||
Logging.configure({console: bridgeSdkLevel });
|
||||
Logger.configure({
|
||||
console: config.logging.level,
|
||||
colorize: config.logging.colorize,
|
||||
json: config.logging.json,
|
||||
timestampFormat: config.logging.timestampFormat
|
||||
});
|
||||
LogService.setLogger(Logger.botSdkLogger);
|
||||
|
||||
if (config.queue.monolithic) {
|
||||
const matrixSender = new MatrixSender(config, registration);
|
||||
@ -49,7 +52,7 @@ async function start() {
|
||||
}
|
||||
|
||||
start().catch((ex) => {
|
||||
if (LogWrapper.root.configured) {
|
||||
if (Logger.root.configured) {
|
||||
log.error("BridgeApp encountered an error and has stopped:", ex);
|
||||
} else {
|
||||
// eslint-disable-next-line no-console
|
||||
|
@ -1,17 +1,24 @@
|
||||
import { BridgeConfig } from "../Config/Config";
|
||||
import { Webhooks } from "../Webhooks";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { UserNotificationWatcher } from "../Notifications/UserNotificationWatcher";
|
||||
import Metrics from "../Metrics";
|
||||
import { ListenerService } from "../ListenerService";
|
||||
import { LogService } from "matrix-bot-sdk";
|
||||
|
||||
|
||||
const log = new LogWrapper("App");
|
||||
const log = new Logger("App");
|
||||
|
||||
async function start() {
|
||||
const configFile = process.argv[2] || "./config.yml";
|
||||
const config = await BridgeConfig.parseConfig(configFile, process.env);
|
||||
LogWrapper.root.configureLogging(config.logging);
|
||||
Logger.configure({
|
||||
console: config.logging.level,
|
||||
colorize: config.logging.colorize,
|
||||
json: config.logging.json,
|
||||
timestampFormat: config.logging.timestampFormat
|
||||
});
|
||||
LogService.setLogger(Logger.botSdkLogger);
|
||||
const listener = new ListenerService(config.listeners);
|
||||
if (config.metrics) {
|
||||
if (!config.metrics.port) {
|
||||
|
@ -1,18 +1,25 @@
|
||||
import { BridgeConfig, parseRegistrationFile } from "../Config/Config";
|
||||
import { MatrixSender } from "../MatrixSender";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import Metrics from "../Metrics";
|
||||
import { ListenerService } from "../ListenerService";
|
||||
import { LogService } from "matrix-bot-sdk";
|
||||
|
||||
|
||||
const log = new LogWrapper("App");
|
||||
const log = new Logger("App");
|
||||
|
||||
async function start() {
|
||||
const configFile = process.argv[2] || "./config.yml";
|
||||
const registrationFile = process.argv[3] || "./registration.yml";
|
||||
const config = await BridgeConfig.parseConfig(configFile, process.env);
|
||||
const registration = await parseRegistrationFile(registrationFile);
|
||||
LogWrapper.root.configureLogging(config.logging);
|
||||
Logger.configure({
|
||||
console: config.logging.level,
|
||||
colorize: config.logging.colorize,
|
||||
json: config.logging.json,
|
||||
timestampFormat: config.logging.timestampFormat
|
||||
});
|
||||
LogService.setLogger(Logger.botSdkLogger);
|
||||
const listener = new ListenerService(config.listeners);
|
||||
const sender = new MatrixSender(config, registration);
|
||||
if (config.metrics) {
|
||||
|
@ -26,7 +26,7 @@ import { retry } from "./PromiseUtil";
|
||||
import { UserNotificationsEvent } from "./Notifications/UserNotificationWatcher";
|
||||
import { UserTokenStore } from "./UserTokenStore";
|
||||
import * as GitHubWebhookTypes from "@octokit/webhooks-types";
|
||||
import LogWrapper from "./LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { Provisioner } from "./provisioning/provisioner";
|
||||
import { JiraProvisionerRouter } from "./Jira/Router";
|
||||
import { GitHubProvisionerRouter } from "./Github/Router";
|
||||
@ -41,7 +41,7 @@ import { JiraOAuthRequestCloud, JiraOAuthRequestOnPrem, JiraOAuthRequestResult }
|
||||
import { GenericWebhookEvent, GenericWebhookEventResult } from "./generic/types";
|
||||
import { SetupWidget } from "./Widgets/SetupWidget";
|
||||
import { FeedEntry, FeedError, FeedReader, FeedSuccess } from "./feeds/FeedReader";
|
||||
const log = new LogWrapper("Bridge");
|
||||
const log = new Logger("Bridge");
|
||||
|
||||
export class Bridge {
|
||||
private readonly as: Appservice;
|
||||
|
@ -3,7 +3,7 @@ import markdown from "markdown-it";
|
||||
import mime from "mime";
|
||||
import emoji from "node-emoji";
|
||||
import { MatrixMessageContent, MatrixEvent } from "./MatrixEvent";
|
||||
import LogWrapper from "./LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import axios from "axios";
|
||||
import { FormatUtil } from "./FormatUtil";
|
||||
import { IssuesGetCommentResponseData, ReposGetResponseData, IssuesGetResponseData } from "./Github/Types"
|
||||
@ -13,7 +13,7 @@ const REGEX_MENTION = /(^|\s)(@[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38})(\s|$)/ig;
|
||||
const REGEX_MATRIX_MENTION = /<a href="https:\/\/matrix\.to\/#\/(.+)">(.*)<\/a>/gmi;
|
||||
const REGEX_IMAGES = /!\[.*]\((.*\.(\w+))\)/gm;
|
||||
const md = new markdown();
|
||||
const log = new LogWrapper("CommentProcessor");
|
||||
const log = new Logger("CommentProcessor");
|
||||
|
||||
interface IMatrixCommentEvent extends MatrixMessageContent {
|
||||
// eslint-disable-next-line camelcase
|
||||
|
@ -6,12 +6,12 @@ import { configKey, hideKey } from "./Decorators";
|
||||
import { BridgeConfigListener, ResourceTypeArray } from "../ListenerService";
|
||||
import { GitHubRepoConnectionOptions } from "../Connections/GithubRepo";
|
||||
import { BridgeConfigActorPermission, BridgePermissions } from "../libRs";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { ConfigError } from "../errors";
|
||||
import { ApiError, ErrCode } from "../api";
|
||||
import { GITHUB_CLOUD_URL } from "../Github/GithubInstance";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
|
||||
const log = new LogWrapper("Config");
|
||||
const log = new Logger("Config");
|
||||
|
||||
function makePrefixedUrl(urlString: string): URL {
|
||||
return new URL(urlString.endsWith("/") ? urlString : urlString + "/");
|
||||
@ -664,7 +664,7 @@ export async function parseRegistrationFile(filename: string) {
|
||||
|
||||
// Can be called directly
|
||||
if (require.main === module) {
|
||||
LogWrapper.root.configureLogging({level: "info"});
|
||||
Logger.configure({console: "info"});
|
||||
BridgeConfig.parseConfig(process.argv[2] || "config.yml", process.env).then(() => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Config successfully validated.');
|
||||
|
@ -11,7 +11,7 @@ import { ConnectionDeclarations, GenericHookConnection, GitHubDiscussionConnecti
|
||||
import { GithubInstance } from "./Github/GithubInstance";
|
||||
import { GitLabClient } from "./Gitlab/Client";
|
||||
import { JiraProject } from "./Jira/Types";
|
||||
import LogWrapper from "./LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { MessageSenderClient } from "./MatrixSender";
|
||||
import { GetConnectionTypeResponseItem } from "./provisioning/api";
|
||||
import { ApiError, ErrCode } from "./api";
|
||||
@ -21,7 +21,7 @@ import { IBridgeStorageProvider } from "./Stores/StorageProvider";
|
||||
import Metrics from "./Metrics";
|
||||
import EventEmitter from "events";
|
||||
|
||||
const log = new LogWrapper("ConnectionManager");
|
||||
const log = new Logger("ConnectionManager");
|
||||
|
||||
export class ConnectionManager extends EventEmitter {
|
||||
private connections: IConnection[] = [];
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { botCommand, BotCommands, handleCommand, HelpFunction } from "../BotCommands";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { MatrixClient } from "matrix-bot-sdk";
|
||||
import { MatrixMessageContent, MatrixEvent } from "../MatrixEvent";
|
||||
import { BaseConnection } from "./BaseConnection";
|
||||
import { IConnectionState, PermissionCheckFn } from ".";
|
||||
const log = new LogWrapper("CommandConnection");
|
||||
const log = new Logger("CommandConnection");
|
||||
|
||||
/**
|
||||
* Connection class that handles commands for a given connection. Should be used
|
||||
|
@ -3,7 +3,7 @@ import { IConnection, IConnectionState, InstantiateConnectionOpts } from ".";
|
||||
import { ApiError, ErrCode } from "../api";
|
||||
import { BridgeConfigFeeds } from "../Config/Config";
|
||||
import { FeedEntry, FeedError} from "../feeds/FeedReader";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { IBridgeStorageProvider } from "../Stores/StorageProvider";
|
||||
import { BaseConnection } from "./BaseConnection";
|
||||
import axios from "axios";
|
||||
@ -11,7 +11,7 @@ import markdown from "markdown-it";
|
||||
import { Connection, ProvisionConnectionOpts } from "./IConnection";
|
||||
import { GetConnectionsResponseItem } from "../provisioning/api";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
const log = new LogWrapper("FeedConnection");
|
||||
const log = new Logger("FeedConnection");
|
||||
const md = new markdown();
|
||||
|
||||
export interface LastResultOk {
|
||||
|
@ -3,12 +3,12 @@ import markdownit from "markdown-it";
|
||||
import { FigmaPayload } from "../figma/types";
|
||||
import { BaseConnection } from "./BaseConnection";
|
||||
import { IConnection, IConnectionState } from ".";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { IBridgeStorageProvider } from "../Stores/StorageProvider";
|
||||
import { BridgeConfigFigma } from "../Config/Config";
|
||||
import { Connection, InstantiateConnectionOpts, ProvisionConnectionOpts } from "./IConnection";
|
||||
|
||||
const log = new LogWrapper("FigmaFileConnection");
|
||||
const log = new Logger("FigmaFileConnection");
|
||||
|
||||
export interface FigmaFileConnectionState extends IConnectionState {
|
||||
fileId: string;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Connection, IConnection, IConnectionState, InstantiateConnectionOpts, ProvisionConnectionOpts } from "./IConnection";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { MessageSenderClient } from "../MatrixSender"
|
||||
import markdownit from "markdown-it";
|
||||
import { VMScript as Script, NodeVM } from "vm2";
|
||||
@ -52,7 +52,7 @@ interface WebhookTransformationResult {
|
||||
empty?: boolean;
|
||||
}
|
||||
|
||||
const log = new LogWrapper("GenericHookConnection");
|
||||
const log = new Logger("GenericHookConnection");
|
||||
const md = new markdownit();
|
||||
|
||||
const TRANSFORMATION_TIMEOUT_MS = 500;
|
||||
|
@ -10,7 +10,7 @@ import emoji from "node-emoji";
|
||||
import markdown from "markdown-it";
|
||||
import { DiscussionCommentCreatedEvent } from "@octokit/webhooks-types";
|
||||
import { GithubGraphQLClient } from "../Github/GithubInstance";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { BaseConnection } from "./BaseConnection";
|
||||
import { BridgeConfigGitHub } from "../Config/Config";
|
||||
export interface GitHubDiscussionConnectionState {
|
||||
@ -22,7 +22,7 @@ export interface GitHubDiscussionConnectionState {
|
||||
category: number;
|
||||
}
|
||||
|
||||
const log = new LogWrapper("GitHubDiscussion");
|
||||
const log = new Logger("GitHubDiscussion");
|
||||
const md = new markdown();
|
||||
|
||||
/**
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { Connection, IConnection, InstantiateConnectionOpts } from "./IConnection";
|
||||
import { Appservice, Space, StateEvent } from "matrix-bot-sdk";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { ReposGetResponseData } from "../Github/Types";
|
||||
import axios from "axios";
|
||||
import { GitHubDiscussionConnection } from "./GithubDiscussion";
|
||||
import { GithubInstance } from "../Github/GithubInstance";
|
||||
import { BaseConnection } from "./BaseConnection";
|
||||
|
||||
const log = new LogWrapper("GitHubDiscussionSpace");
|
||||
const log = new Logger("GitHubDiscussionSpace");
|
||||
|
||||
export interface GitHubDiscussionSpaceConnectionState {
|
||||
owner: string;
|
||||
|
@ -3,7 +3,7 @@ import { Appservice, StateEvent } from "matrix-bot-sdk";
|
||||
import { MatrixMessageContent, MatrixEvent } from "../MatrixEvent";
|
||||
import markdown from "markdown-it";
|
||||
import { UserTokenStore } from "../UserTokenStore";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { CommentProcessor } from "../CommentProcessor";
|
||||
import { MessageSenderClient } from "../MatrixSender";
|
||||
import { getIntentForUser } from "../IntentUtils";
|
||||
@ -24,7 +24,7 @@ export interface GitHubIssueConnectionState {
|
||||
comments_processed: number;
|
||||
}
|
||||
|
||||
const log = new LogWrapper("GitHubIssueConnection");
|
||||
const log = new Logger("GitHubIssueConnection");
|
||||
const md = new markdown();
|
||||
|
||||
interface IQueryRoomOpts {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Connection, IConnection, InstantiateConnectionOpts } from "./IConnection";
|
||||
import { Appservice, StateEvent } from "matrix-bot-sdk";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { ProjectsGetResponseData } from "../Github/Types";
|
||||
import { BaseConnection } from "./BaseConnection";
|
||||
|
||||
@ -9,7 +9,7 @@ export interface GitHubProjectConnectionState {
|
||||
project_id: number;
|
||||
state: "open"|"closed";
|
||||
}
|
||||
const log = new LogWrapper("GitHubProjectConnection");
|
||||
const log = new Logger("GitHubProjectConnection");
|
||||
|
||||
/**
|
||||
* Handles rooms connected to a GitHub project.
|
||||
|
@ -13,7 +13,7 @@ import { NAMELESS_ORG_PLACEHOLDER, ReposGetResponseData } from "../Github/Types"
|
||||
import { UserTokenStore } from "../UserTokenStore";
|
||||
import axios, { AxiosError } from "axios";
|
||||
import emoji from "node-emoji";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import markdown from "markdown-it";
|
||||
import { CommandConnection } from "./CommandConnection";
|
||||
import { GithubInstance } from "../Github/GithubInstance";
|
||||
@ -24,7 +24,7 @@ import { PermissionCheckFn } from ".";
|
||||
import { MinimalGitHubIssue, MinimalGitHubRepo } from "../libRs";
|
||||
import Ajv, { JSONSchemaType } from "ajv";
|
||||
|
||||
const log = new LogWrapper("GitHubRepoConnection");
|
||||
const log = new Logger("GitHubRepoConnection");
|
||||
const md = new markdown();
|
||||
|
||||
interface IQueryRoomOpts {
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { Connection, IConnection, InstantiateConnectionOpts } from "./IConnection";
|
||||
import { Appservice, Space, StateEvent } from "matrix-bot-sdk";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import axios from "axios";
|
||||
import { GitHubDiscussionSpace } from ".";
|
||||
import { GithubInstance } from "../Github/GithubInstance";
|
||||
import { BaseConnection } from "./BaseConnection";
|
||||
|
||||
const log = new LogWrapper("GitHubOwnerSpace");
|
||||
const log = new Logger("GitHubOwnerSpace");
|
||||
|
||||
export interface GitHubUserSpaceConnectionState {
|
||||
username: string;
|
||||
|
@ -2,7 +2,7 @@ import { Connection, IConnection, InstantiateConnectionOpts } from "./IConnectio
|
||||
import { Appservice, StateEvent } from "matrix-bot-sdk";
|
||||
import { MatrixMessageContent, MatrixEvent } from "../MatrixEvent";
|
||||
import { UserTokenStore } from "../UserTokenStore";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { CommentProcessor } from "../CommentProcessor";
|
||||
import { MessageSenderClient } from "../MatrixSender";
|
||||
import { BridgeConfigGitLab, GitLabInstance } from "../Config/Config";
|
||||
@ -20,7 +20,7 @@ export interface GitLabIssueConnectionState {
|
||||
authorName: string;
|
||||
}
|
||||
|
||||
const log = new LogWrapper("GitLabIssueConnection");
|
||||
const log = new Logger("GitLabIssueConnection");
|
||||
|
||||
// interface IQueryRoomOpts {
|
||||
// as: Appservice;
|
||||
|
@ -5,7 +5,7 @@ import { Appservice, StateEvent } from "matrix-bot-sdk";
|
||||
import { BotCommands, botCommand, compileBotCommands } from "../BotCommands";
|
||||
import { MatrixMessageContent } from "../MatrixEvent";
|
||||
import markdown from "markdown-it";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { BridgeConfigGitLab, GitLabInstance } from "../Config/Config";
|
||||
import { IGitlabMergeRequest, IGitlabProject, IGitlabUser, IGitLabWebhookMREvent, IGitLabWebhookNoteEvent, IGitLabWebhookPushEvent, IGitLabWebhookReleaseEvent, IGitLabWebhookTagPushEvent, IGitLabWebhookWikiPageEvent } from "../Gitlab/WebhookTypes";
|
||||
import { CommandConnection } from "./CommandConnection";
|
||||
@ -37,7 +37,7 @@ export interface GitLabRepoConnectionProjectTarget {
|
||||
|
||||
export type GitLabRepoConnectionTarget = GitLabRepoConnectionInstanceTarget|GitLabRepoConnectionProjectTarget;
|
||||
|
||||
const log = new LogWrapper("GitLabRepoConnection");
|
||||
const log = new Logger("GitLabRepoConnection");
|
||||
const md = new markdown();
|
||||
|
||||
const PUSH_MAX_COMMITS = 5;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Connection, IConnection, IConnectionState, InstantiateConnectionOpts, ProvisionConnectionOpts } from "./IConnection";
|
||||
import { Appservice, StateEvent } from "matrix-bot-sdk";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { JiraIssueEvent, JiraIssueUpdatedEvent } from "../Jira/WebhookTypes";
|
||||
import { FormatUtil } from "../FormatUtil";
|
||||
import markdownit from "markdown-it";
|
||||
@ -66,7 +66,7 @@ function validateJiraConnectionState(state: unknown): JiraProjectConnectionState
|
||||
return {url, commandPrefix, events, priority};
|
||||
}
|
||||
|
||||
const log = new LogWrapper("JiraProjectConnection");
|
||||
const log = new Logger("JiraProjectConnection");
|
||||
const md = new markdownit();
|
||||
|
||||
/**
|
||||
|
@ -13,10 +13,9 @@ import { SetupWidget } from "../Widgets/SetupWidget";
|
||||
import { AdminRoom } from "../AdminRoom";
|
||||
import { GitLabRepoConnection } from "./GitlabRepo";
|
||||
import { IConnectionState, ProvisionConnectionOpts } from "./IConnection";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { ApiError } from "matrix-appservice-bridge";
|
||||
import { ApiError, Logger } from "matrix-appservice-bridge";
|
||||
const md = new markdown();
|
||||
const log = new LogWrapper("SetupConnection");
|
||||
const log = new Logger("SetupConnection");
|
||||
|
||||
/**
|
||||
* Handles setting up a room with connections. This connection is "virtual" in that it has
|
||||
|
@ -1,13 +1,12 @@
|
||||
import qs from "querystring";
|
||||
import { AdminRoomCommandHandler, Category } from "../AdminRoomCommandHandler"
|
||||
import { botCommand } from "../BotCommands";
|
||||
import { CommandError, TokenError, TokenErrorCode } from "../errors";
|
||||
import { GithubInstance } from "./GithubInstance";
|
||||
import { GitHubOAuthToken } from "./Types";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { BridgePermissionLevel } from "../Config/Config";
|
||||
|
||||
const log = new LogWrapper('GitHubBotCommands');
|
||||
const log = new Logger('GitHubBotCommands');
|
||||
export class GitHubBotCommands extends AdminRoomCommandHandler {
|
||||
@botCommand("github login", {help: "Log in to GitHub", category: Category.Github, permissionLevel: BridgePermissionLevel.login})
|
||||
public async loginCommand() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { createAppAuth } from "@octokit/auth-app";
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { DiscussionQLResponse, DiscussionQL } from "./Discussion";
|
||||
import * as GitHubWebhookTypes from "@octokit/webhooks-types";
|
||||
import { GitHubOAuthTokenResponse, InstallationDataType } from "./Types";
|
||||
@ -8,7 +8,7 @@ import axios from "axios";
|
||||
import qs from "querystring";
|
||||
import UserAgent from "../UserAgent";
|
||||
|
||||
const log = new LogWrapper("GithubInstance");
|
||||
const log = new Logger("GithubInstance");
|
||||
|
||||
export const GITHUB_CLOUD_URL = new URL("https://api.github.com");
|
||||
|
||||
|
@ -2,11 +2,11 @@ import { Router, Request, Response, NextFunction } from "express";
|
||||
import { BridgeConfigGitHub } from "../Config/Config";
|
||||
import { ApiError, ErrCode } from "../api";
|
||||
import { UserTokenStore } from "../UserTokenStore";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { GithubInstance } from "./GithubInstance";
|
||||
import { NAMELESS_ORG_PLACEHOLDER } from "./Types";
|
||||
|
||||
const log = new LogWrapper("GitHubProvisionerRouter");
|
||||
const log = new Logger("GitHubProvisionerRouter");
|
||||
interface GitHubAccountStatus {
|
||||
loggedIn: boolean;
|
||||
username?: string;
|
||||
|
@ -1,11 +1,11 @@
|
||||
import axios from "axios";
|
||||
import { GitLabInstance } from "../Config/Config";
|
||||
import { GetIssueResponse, GetUserResponse, CreateIssueOpts, CreateIssueResponse, GetIssueOpts, EditIssueOpts, GetTodosResponse, EventsOpts, CreateIssueNoteOpts, CreateIssueNoteResponse, GetProjectResponse, ProjectHook, ProjectHookOpts, AccessLevel, SimpleProject } from "./Types";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { URLSearchParams } from "url";
|
||||
import UserAgent from "../UserAgent";
|
||||
|
||||
const log = new LogWrapper("GitLabClient");
|
||||
const log = new Logger("GitLabClient");
|
||||
|
||||
/**
|
||||
* A GitLab project used inside a URL may either be the ID of the project, or the encoded path of the project.
|
||||
|
@ -1,8 +1,8 @@
|
||||
import LogWrapper from "./LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { Appservice } from "matrix-bot-sdk";
|
||||
import axios from "axios";
|
||||
|
||||
const log = new LogWrapper("IntentUtils");
|
||||
const log = new Logger("IntentUtils");
|
||||
|
||||
export async function getIntentForUser(user: {avatarUrl?: string, login: string}, as: Appservice, prefix: string) {
|
||||
const domain = as.botUserId.split(":")[1];
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { AdminRoomCommandHandler, Category } from "../AdminRoomCommandHandler";
|
||||
import { botCommand } from "../BotCommands";
|
||||
import { JiraAPIAccessibleResource } from "./Types";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { BridgePermissionLevel } from "../Config/Config";
|
||||
|
||||
const log = new LogWrapper('JiraBotCommands');
|
||||
const log = new Logger('JiraBotCommands');
|
||||
|
||||
export class JiraBotCommands extends AdminRoomCommandHandler {
|
||||
@botCommand("jira login", {help: "Log in to JIRA", category: Category.Jira, permissionLevel: BridgePermissionLevel.login})
|
||||
|
@ -2,12 +2,12 @@ import { BridgeConfigJira } from "../Config/Config";
|
||||
import { MessageQueue } from "../MessageQueue";
|
||||
import { Router, Request, Response, NextFunction, json } from "express";
|
||||
import { UserTokenStore } from "../UserTokenStore";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { ApiError, ErrCode } from "../api";
|
||||
import { JiraOAuthRequestCloud, JiraOAuthRequestOnPrem, JiraOAuthRequestResult } from "./OAuth";
|
||||
import { HookshotJiraApi } from "./Client";
|
||||
|
||||
const log = new LogWrapper("JiraRouter");
|
||||
const log = new Logger("JiraRouter");
|
||||
|
||||
interface OAuthQueryCloud {
|
||||
state: string;
|
||||
|
@ -3,11 +3,11 @@ import axios from 'axios';
|
||||
import QuickLRU from "@alloc/quick-lru";
|
||||
import { JiraAPIAccessibleResource, JiraIssue, JiraOAuthResult, JiraProject, JiraCloudProjectSearchResponse, JiraStoredToken } from '../Types';
|
||||
import { BridgeConfigJira, BridgeConfigJiraCloudOAuth } from '../../Config/Config';
|
||||
import LogWrapper from '../../LogWrapper';
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { HookshotJiraApi, JiraClient } from '../Client';
|
||||
import JiraApi from 'jira-client';
|
||||
|
||||
const log = new LogWrapper("JiraCloudClient");
|
||||
const log = new Logger("JiraCloudClient");
|
||||
const ACCESSIBLE_RESOURCE_CACHE_LIMIT = 100;
|
||||
const ACCESSIBLE_RESOURCE_CACHE_TTL_MS = 60000;
|
||||
|
||||
|
@ -3,7 +3,7 @@ import Axios, { Method } from "axios"
|
||||
import qs from "querystring";
|
||||
import { createPrivateKey, createSign, KeyObject } from "crypto";
|
||||
import fs from "fs";
|
||||
import Logger from "../../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { encodeJiraToken, JiraOAuth } from "../OAuth";
|
||||
import { JiraOAuthResult } from "../Types";
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Server } from "http";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { Application, default as expressApp, NextFunction, Request, Response, Router } from "express";
|
||||
import LogWrapper from "./LogWrapper";
|
||||
import { errorMiddleware } from "./api";
|
||||
|
||||
// Appserices can't be handled yet because the bot-sdk maintains control of it.
|
||||
@ -14,7 +14,7 @@ export interface BridgeConfigListener {
|
||||
resources: Array<ResourceName>;
|
||||
}
|
||||
|
||||
const log = new LogWrapper("ListenerService");
|
||||
const log = new Logger("ListenerService");
|
||||
|
||||
export class ListenerService {
|
||||
private readonly listeners: {
|
||||
|
@ -1,210 +0,0 @@
|
||||
import { LogLevel, LogService } from "matrix-bot-sdk";
|
||||
import util from "util";
|
||||
import winston, { format } from "winston";
|
||||
import { BridgeConfigLogging } from "./Config/Config";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type MsgType = string|Error|any|{error?: string};
|
||||
|
||||
function isMessageNoise(messageOrObject: MsgType[]) {
|
||||
const error = messageOrObject[0]?.error || messageOrObject[1]?.error || messageOrObject[1]?.body?.error;
|
||||
const errcode = messageOrObject[0]?.errcode || messageOrObject[1]?.errcode;
|
||||
if (errcode === "M_NOT_FOUND" && error === "Room account data not found") {
|
||||
return true;
|
||||
}
|
||||
if (errcode === "M_NOT_FOUND" && error === "Account data not found") {
|
||||
return true;
|
||||
}
|
||||
if (errcode === "M_NOT_FOUND" && error === "Event not found.") {
|
||||
return true;
|
||||
}
|
||||
if (errcode === "M_USER_IN_USE") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
interface HookshotLogInfo extends winston.Logform.TransformableInfo {
|
||||
data: MsgType[];
|
||||
}
|
||||
export class GlobalLogger {
|
||||
private isConfigured = false;
|
||||
|
||||
public get configured() {
|
||||
return this.isConfigured;
|
||||
}
|
||||
|
||||
private winstonLog?: winston.Logger;
|
||||
|
||||
public get winston() {
|
||||
return this.winstonLog;
|
||||
}
|
||||
|
||||
public configureLogging(cfg: BridgeConfigLogging, debugStream?: NodeJS.WritableStream) {
|
||||
if (typeof cfg === "string") {
|
||||
cfg = { level: cfg };
|
||||
}
|
||||
|
||||
this.winstonLog?.close();
|
||||
|
||||
const formatters = [
|
||||
winston.format.timestamp({
|
||||
format: cfg.timestampFormat || "HH:mm:ss:SSS",
|
||||
}),
|
||||
(format((info) => {
|
||||
info.level = info.level.toUpperCase();
|
||||
return info;
|
||||
}))(),
|
||||
]
|
||||
|
||||
if (!cfg.json && cfg.colorize) {
|
||||
formatters.push(
|
||||
winston.format.colorize({
|
||||
level: true,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (cfg.json) {
|
||||
formatters.push((format((info) => {
|
||||
const hsData = [...(info as HookshotLogInfo).data];
|
||||
const firstArg = hsData.shift() ?? 'undefined';
|
||||
const result: winston.Logform.TransformableInfo = {
|
||||
level: info.level,
|
||||
module: info.module,
|
||||
timestamp: info.timestamp,
|
||||
// Find the first instance of an error, subsequent errors are treated as args.
|
||||
error: hsData.find(d => d instanceof Error)?.message,
|
||||
message: "", // Always filled out
|
||||
args: hsData.length ? hsData : undefined,
|
||||
};
|
||||
|
||||
if (typeof firstArg === "string") {
|
||||
result.message = firstArg;
|
||||
} else if (firstArg instanceof Error) {
|
||||
result.message = firstArg.message;
|
||||
} else {
|
||||
result.message = util.inspect(firstArg);
|
||||
}
|
||||
|
||||
return result;
|
||||
}))()),
|
||||
formatters.push(winston.format.json());
|
||||
} else {
|
||||
formatters.push(winston.format.printf(i => LogWrapper.messageFormatter(i as HookshotLogInfo)));
|
||||
}
|
||||
|
||||
const formatter = winston.format.combine(...formatters);
|
||||
const log = this.winstonLog = winston.createLogger({
|
||||
level: cfg.level,
|
||||
transports: [
|
||||
debugStream ? new winston.transports.Stream({
|
||||
stream: debugStream,
|
||||
format: formatter,
|
||||
}) :
|
||||
new winston.transports.Console({
|
||||
format: formatter,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
function formatBotSdkMessage(module: string, ...messageOrObject: MsgType[]) {
|
||||
return {
|
||||
module,
|
||||
data: [LogWrapper.formatMsgTypeArray(messageOrObject)]
|
||||
};
|
||||
}
|
||||
|
||||
LogService.setLogger({
|
||||
info: (module: string, ...messageOrObject: MsgType[]) => {
|
||||
// These are noisy, redirect to debug.
|
||||
if (module.startsWith("MatrixLiteClient") || module.startsWith("MatrixHttpClient")) {
|
||||
log.log("debug", formatBotSdkMessage(module, ...messageOrObject));
|
||||
return;
|
||||
}
|
||||
log.log("info", formatBotSdkMessage(module, ...messageOrObject));
|
||||
},
|
||||
warn: (module: string, ...messageOrObject: MsgType[]) => {
|
||||
if (isMessageNoise(messageOrObject)) {
|
||||
log.log("debug", formatBotSdkMessage(module, ...messageOrObject));
|
||||
return;
|
||||
}
|
||||
log.log("warn", formatBotSdkMessage(module, ...messageOrObject));
|
||||
},
|
||||
error: (module: string, ...messageOrObject: MsgType[]) => {
|
||||
if (isMessageNoise(messageOrObject)) {
|
||||
log.log("debug", formatBotSdkMessage(module, ...messageOrObject));
|
||||
return;
|
||||
}
|
||||
log.log("error", formatBotSdkMessage(module, ...messageOrObject));
|
||||
},
|
||||
debug: (module: string, ...messageOrObject: MsgType[]) => {
|
||||
log.log("debug", formatBotSdkMessage(module, ...messageOrObject));
|
||||
},
|
||||
trace: (module: string, ...messageOrObject: MsgType[]) => {
|
||||
log.log("verbose", formatBotSdkMessage(module, ...messageOrObject));
|
||||
},
|
||||
});
|
||||
|
||||
LogService.setLevel(LogLevel.fromString(cfg.level));
|
||||
LogService.debug("LogWrapper", "Reconfigured logging");
|
||||
this.isConfigured = true;
|
||||
}
|
||||
}
|
||||
export default class LogWrapper {
|
||||
static readonly root = new GlobalLogger();
|
||||
|
||||
static formatMsgTypeArray(...data: MsgType[]): string {
|
||||
data = data.flat();
|
||||
return data.map(obj => {
|
||||
if (typeof obj === "string") {
|
||||
return obj;
|
||||
}
|
||||
return util.inspect(obj);
|
||||
}).join(" ");
|
||||
}
|
||||
|
||||
static messageFormatter(info: HookshotLogInfo): string {
|
||||
const logPrefix = `${info.level} ${info.timestamp} [${info.module}] `;
|
||||
return logPrefix + this.formatMsgTypeArray(info.data ?? []);
|
||||
}
|
||||
|
||||
constructor(private module: string, private readonly logger: GlobalLogger = LogWrapper.root) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs to the DEBUG channel
|
||||
* @param msg The message or data to log.
|
||||
* @param additionalData Additional context.
|
||||
*/
|
||||
public debug(msg: MsgType, ...additionalData: MsgType[]) {
|
||||
this.logger.winston?.log("debug", { module: this.module, data: [msg, ...additionalData] });
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs to the ERROR channel
|
||||
* @param msg The message or data to log.
|
||||
* @param additionalData Additional context.
|
||||
*/
|
||||
public error(msg: MsgType, ...additionalData: MsgType[]) {
|
||||
this.logger.winston?.log("error", { module: this.module, data: [msg, ...additionalData] });
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs to the INFO channel
|
||||
* @param msg The message or data to log.
|
||||
* @param additionalData Additional context.
|
||||
*/
|
||||
public info(msg: MsgType, ...additionalData: MsgType[]) {
|
||||
this.logger.winston?.log("info", { module: this.module, data: [msg, ...additionalData] });
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs to the WARN channel
|
||||
* @param msg The message or data to log.
|
||||
* @param additionalData Additional context.
|
||||
*/
|
||||
public warn(msg: MsgType, ...additionalData: MsgType[]) {
|
||||
this.logger.winston?.log("warn", { module: this.module, data: [msg, ...additionalData] });
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import { BridgeConfig } from "./Config/Config";
|
||||
import { MessageQueue, createMessageQueue } from "./MessageQueue";
|
||||
import { Appservice, IAppserviceRegistration, MemoryStorageProvider } from "matrix-bot-sdk";
|
||||
import LogWrapper from "./LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { v4 as uuid } from "uuid";
|
||||
import { getAppservice } from "./appservice";
|
||||
import Metrics from "./Metrics";
|
||||
@ -22,7 +22,7 @@ export interface IMatrixSendMessageFailedResponse {
|
||||
}
|
||||
|
||||
|
||||
const log = new LogWrapper("MatrixSender");
|
||||
const log = new Logger("MatrixSender");
|
||||
|
||||
export class MatrixSender {
|
||||
private mq: MessageQueue;
|
||||
|
@ -3,11 +3,11 @@ import { MessageQueue, MessageQueueMessage, DEFAULT_RES_TIMEOUT, MessageQueueMes
|
||||
import { Redis, default as redis } from "ioredis";
|
||||
import { BridgeConfig, BridgeConfigQueue } from "../Config/Config";
|
||||
import { EventEmitter } from "events";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
|
||||
import {v4 as uuid} from "uuid";
|
||||
|
||||
const log = new LogWrapper("RedisMq");
|
||||
const log = new Logger("RedisMq");
|
||||
|
||||
const CONSUMER_TRACK_PREFIX = "consumers.";
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Appservice, FunctionCallContext, METRIC_MATRIX_CLIENT_FAILED_FUNCTION_CALL, METRIC_MATRIX_CLIENT_SUCCESSFUL_FUNCTION_CALL } from "matrix-bot-sdk";
|
||||
import { collectDefaultMetrics, Counter, Gauge, register, Registry } from "prom-client";
|
||||
import { Response, Router } from "express";
|
||||
import LogWrapper from "./LogWrapper";
|
||||
const log = new LogWrapper("Metrics");
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
const log = new Logger("Metrics");
|
||||
|
||||
export class Metrics {
|
||||
public readonly expressRouter = Router();
|
||||
|
@ -2,11 +2,11 @@ import { Octokit, RestEndpointMethodTypes } from "@octokit/rest";
|
||||
import { EventEmitter } from "events";
|
||||
import { GithubInstance } from "../Github/GithubInstance";
|
||||
import { GitHubUserNotification as HSGitHubUserNotification } from "../Github/Types";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { NotificationWatcherTask } from "./NotificationWatcherTask";
|
||||
import { RequestError } from "@octokit/request-error";
|
||||
import Metrics from "../Metrics";
|
||||
const log = new LogWrapper("GitHubWatcher");
|
||||
const log = new Logger("GitHubWatcher");
|
||||
|
||||
const GH_API_THRESHOLD = 50;
|
||||
const GH_API_RETRY_IN = 1000 * 60;
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { EventEmitter } from "events";
|
||||
import { GitLabClient } from "../Gitlab/Client";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { NotificationWatcherTask } from "./NotificationWatcherTask";
|
||||
|
||||
const log = new LogWrapper("GitLabWatcher");
|
||||
const log = new Logger("GitLabWatcher");
|
||||
|
||||
export class GitLabWatcher extends EventEmitter implements NotificationWatcherTask {
|
||||
private client: GitLabClient;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { NotificationsDisableEvent, NotificationsEnableEvent } from "../Webhooks";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { createMessageQueue, MessageQueue, MessageQueueMessage } from "../MessageQueue";
|
||||
import { MessageSenderClient } from "../MatrixSender";
|
||||
import { NotificationWatcherTask } from "./NotificationWatcherTask";
|
||||
@ -17,7 +17,7 @@ export interface UserNotificationsEvent {
|
||||
const MIN_INTERVAL_MS = 15000;
|
||||
const FAILURE_THRESHOLD = 50;
|
||||
|
||||
const log = new LogWrapper("UserNotificationWatcher");
|
||||
const log = new Logger("UserNotificationWatcher");
|
||||
|
||||
export class UserNotificationWatcher {
|
||||
/* Key: userId:type:instanceUrl */
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { MessageSenderClient } from "./MatrixSender";
|
||||
import { IBridgeStorageProvider } from "./Stores/StorageProvider";
|
||||
import { UserNotificationsEvent } from "./Notifications/UserNotificationWatcher";
|
||||
import LogWrapper from "./LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { AdminRoom } from "./AdminRoom";
|
||||
import markdown from "markdown-it";
|
||||
import { FormatUtil } from "./FormatUtil";
|
||||
@ -11,7 +11,7 @@ import { components } from "@octokit/openapi-types/types";
|
||||
import { NotifFilter } from "./NotificationFilters";
|
||||
|
||||
|
||||
const log = new LogWrapper("NotificationProcessor");
|
||||
const log = new Logger("NotificationProcessor");
|
||||
const md = new markdown();
|
||||
|
||||
export interface IssueDiff {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import LogWrapper from "./LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
|
||||
const SLEEP_TIME_MS = 250;
|
||||
const DEFAULT_RETRY = () => true;
|
||||
const log = new LogWrapper("PromiseUtil");
|
||||
const log = new Logger("PromiseUtil");
|
||||
|
||||
export async function retry<T>(actionFn: () => Promise<T>,
|
||||
maxAttempts: number,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { IssuesGetResponseData } from "../Github/Types";
|
||||
import { Redis, default as redis } from "ioredis";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
|
||||
import { IBridgeStorageProvider } from "./StorageProvider";
|
||||
import { IFilterInfo } from "matrix-bot-sdk";
|
||||
@ -23,7 +23,7 @@ const ISSUES_LAST_COMMENT_EXPIRE_AFTER = 14 * 24 * 60 * 60; // 7 days
|
||||
const WIDGET_TOKENS = "widgets.tokens.";
|
||||
const WIDGET_USER_TOKENS = "widgets.user-tokens.";
|
||||
|
||||
const log = new LogWrapper("RedisASProvider");
|
||||
const log = new Logger("RedisASProvider");
|
||||
|
||||
export class RedisStorageProvider implements IBridgeStorageProvider {
|
||||
private redis: Redis;
|
||||
|
@ -3,7 +3,7 @@ import { GitLabClient } from "./Gitlab/Client";
|
||||
import { Intent } from "matrix-bot-sdk";
|
||||
import { promises as fs } from "fs";
|
||||
import { publicEncrypt, privateDecrypt } from "crypto";
|
||||
import LogWrapper from "./LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { isJiraCloudInstance, JiraClient } from "./Jira/Client";
|
||||
import { JiraStoredToken } from "./Jira/Types";
|
||||
import { BridgeConfig, BridgeConfigJira, BridgeConfigJiraOnPremOAuth, BridgePermissionLevel } from "./Config/Config";
|
||||
@ -25,7 +25,7 @@ const ACCOUNT_DATA_JIRA_TYPE = "uk.half-shot.matrix-hookshot.jira.password-store
|
||||
const LEGACY_ACCOUNT_DATA_TYPE = "uk.half-shot.matrix-github.password-store:";
|
||||
const LEGACY_ACCOUNT_DATA_GITLAB_TYPE = "uk.half-shot.matrix-github.gitlab.password-store:";
|
||||
|
||||
const log = new LogWrapper("UserTokenStore");
|
||||
const log = new Logger("UserTokenStore");
|
||||
type TokenType = "github"|"gitlab"|"jira";
|
||||
const AllowedTokenTypes = ["github", "gitlab", "jira"];
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { BridgeConfig } from "./Config/Config";
|
||||
import { Router, default as express, Request, Response } from "express";
|
||||
import { EventEmitter } from "events";
|
||||
import { MessageQueue, createMessageQueue } from "./MessageQueue";
|
||||
import LogWrapper from "./LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import qs from "querystring";
|
||||
import axios from "axios";
|
||||
import { IGitLabWebhookEvent, IGitLabWebhookIssueStateEvent, IGitLabWebhookMREvent, IGitLabWebhookReleaseEvent } from "./Gitlab/WebhookTypes";
|
||||
@ -17,7 +17,7 @@ import { GenericWebhooksRouter } from "./generic/Router";
|
||||
import { GithubInstance } from "./Github/GithubInstance";
|
||||
import QuickLRU from "@alloc/quick-lru";
|
||||
|
||||
const log = new LogWrapper("Webhooks");
|
||||
const log = new Logger("Webhooks");
|
||||
|
||||
export interface NotificationsEnableEvent {
|
||||
userId: string;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Application, NextFunction, Response } from "express";
|
||||
import { AdminRoom } from "../AdminRoom";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { ApiError, ErrCode } from "../api";
|
||||
import { BridgeConfig } from "../Config/Config";
|
||||
import { GetConnectionsForServiceResponse } from "./BridgeWidgetInterface";
|
||||
@ -10,7 +10,7 @@ import { ConnectionManager } from "../ConnectionManager";
|
||||
import { assertUserPermissionsInRoom, GetConnectionsResponseItem } from "../provisioning/api";
|
||||
import { Intent, PowerLevelsEvent } from "matrix-bot-sdk";
|
||||
|
||||
const log = new LogWrapper("BridgeWidgetApi");
|
||||
const log = new Logger("BridgeWidgetApi");
|
||||
|
||||
export class BridgeWidgetApi {
|
||||
private readonly api: ProvisioningApi;
|
||||
|
@ -1,10 +1,10 @@
|
||||
|
||||
import { Intent } from "matrix-bot-sdk";
|
||||
import { BridgeWidgetConfig } from "../Config/Config";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { CommandError } from "../errors";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { HookshotWidgetKind } from "./WidgetKind";
|
||||
const log = new LogWrapper("SetupWidget");
|
||||
const log = new Logger("SetupWidget");
|
||||
|
||||
export class SetupWidget {
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { ErrorObject } from "ajv";
|
||||
import { NextFunction, Response, Request } from "express";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import { IApiError } from "matrix-appservice-bridge";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
|
||||
export enum ErrCode {
|
||||
// Errors are prefixed with HS_
|
||||
@ -108,7 +108,7 @@ export class ValidatorApiError extends ApiError {
|
||||
}
|
||||
|
||||
|
||||
export function errorMiddleware(log: LogWrapper) {
|
||||
export function errorMiddleware(log: Logger) {
|
||||
return (err: unknown, _req: Request, res: Response, next: NextFunction) => {
|
||||
if (!err) {
|
||||
next();
|
||||
|
@ -2,7 +2,7 @@ import { MatrixClient } from "matrix-bot-sdk";
|
||||
import { BridgeConfigFeeds } from "../Config/Config";
|
||||
import { ConnectionManager } from "../ConnectionManager";
|
||||
import { FeedConnection } from "../Connections";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { MessageQueue } from "../MessageQueue";
|
||||
|
||||
import Ajv from "ajv";
|
||||
@ -12,7 +12,7 @@ import Metrics from "../Metrics";
|
||||
import UserAgent from "../UserAgent";
|
||||
import { randomUUID } from "crypto";
|
||||
|
||||
const log = new LogWrapper("FeedReader");
|
||||
const log = new Logger("FeedReader");
|
||||
|
||||
export class FeedError extends Error {
|
||||
constructor(
|
||||
|
@ -1,8 +1,10 @@
|
||||
import { BridgeConfigFigma } from "../Config/Config";
|
||||
import * as Figma from 'figma-js';
|
||||
import { MatrixClient } from "matrix-bot-sdk";
|
||||
export * from "./router";
|
||||
export * from "./types";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { AxiosError } from "axios";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
|
||||
export * from "./router";
|
||||
export * from "./types";
|
||||
@ -15,7 +17,7 @@ interface FigmaWebhookDefinition {
|
||||
description: string;
|
||||
}
|
||||
|
||||
const log = new LogWrapper('FigmaWebhooks');
|
||||
const log = new Logger('FigmaWebhooks');
|
||||
|
||||
export async function ensureFigmaWebhooks(figmaConfig: BridgeConfigFigma, matrixClient: MatrixClient) {
|
||||
const publicUrl = figmaConfig.publicUrl;
|
||||
|
@ -2,9 +2,10 @@ import { BridgeConfigFigma } from "../Config/Config";
|
||||
import { MessageQueue } from "../MessageQueue";
|
||||
import { Request, Response, Router, json } from "express";
|
||||
import { FigmaPayload } from "./types";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
|
||||
const log = new Logger('FigmaWebhooksRouter');
|
||||
|
||||
const log = new LogWrapper('FigmaWebhooksRouter');
|
||||
export class FigmaWebhooksRouter {
|
||||
constructor(private readonly config: BridgeConfigFigma, private readonly queue: MessageQueue) { }
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { MessageQueue } from "../MessageQueue";
|
||||
import express, { NextFunction, Request, Response, Router } from "express";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { ApiError, ErrCode } from "../api";
|
||||
import { GenericWebhookEvent, GenericWebhookEventResult } from "./types";
|
||||
import * as xml from "xml2js";
|
||||
|
||||
const WEBHOOK_RESPONSE_TIMEOUT = 5000;
|
||||
|
||||
const log = new LogWrapper('GenericWebhooksRouter');
|
||||
const log = new Logger('GenericWebhooksRouter');
|
||||
export class GenericWebhooksRouter {
|
||||
constructor(private readonly queue: MessageQueue, private readonly deprecatedPath = false, private readonly allowGet: boolean) { }
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Intent, MembershipEventContent, PowerLevelsEventContent } from "matrix-bot-sdk";
|
||||
import { ApiError, ErrCode } from "../api";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
|
||||
export interface GetConnectionTypeResponseItem {
|
||||
eventType: string;
|
||||
@ -16,7 +16,7 @@ export interface GetConnectionsResponseItem<Config = object, Secrets = object> e
|
||||
canEdit?: boolean;
|
||||
}
|
||||
|
||||
const log = new LogWrapper("Provisioner.api");
|
||||
const log = new Logger("Provisioner.api");
|
||||
|
||||
export async function assertUserPermissionsInRoom(userId: string, roomId: string, requiredPermission: "read"|"write", intent: Intent) {
|
||||
try {
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { BridgeConfigProvisioning } from "../Config/Config";
|
||||
import { Router, default as express, NextFunction, Request, Response } from "express";
|
||||
import { ConnectionManager } from "../ConnectionManager";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
import { assertUserPermissionsInRoom, GetConnectionsResponseItem, GetConnectionTypeResponseItem } from "./api";
|
||||
import { ApiError, ErrCode } from "../api";
|
||||
import { Intent } from "matrix-bot-sdk";
|
||||
import Metrics from "../Metrics";
|
||||
|
||||
const log = new LogWrapper("Provisioner");
|
||||
const log = new Logger("Provisioner");
|
||||
|
||||
// Simple validator
|
||||
const ROOM_ID_VALIDATOR = /!.+:.+/;
|
||||
|
@ -1,87 +0,0 @@
|
||||
import { expect } from "chai";
|
||||
import { Writable } from "stream";
|
||||
import LogWrapper, { GlobalLogger } from "../src/LogWrapper";
|
||||
|
||||
const tortureArgs: [unknown, ...unknown[]][] = [
|
||||
["test-msg"],
|
||||
[Number.MAX_VALUE],
|
||||
[false],
|
||||
[Buffer.from('foo')],
|
||||
[new Error('Test')],
|
||||
[undefined],
|
||||
[null],
|
||||
[NaN],
|
||||
[[]],
|
||||
[() => { /*dummy*/}],
|
||||
["Foo", "test-msg"],
|
||||
["Foo", Number.MAX_VALUE],
|
||||
["Foo", false],
|
||||
["Foo", Buffer.from('foo')],
|
||||
["Foo", new Error('Test')],
|
||||
["Foo", undefined],
|
||||
["Foo", null],
|
||||
["Foo", NaN],
|
||||
["Foo", []],
|
||||
["Foo", () => { /*dummy*/}],
|
||||
]
|
||||
|
||||
const MODULE_NAME = 'LogTesting';
|
||||
|
||||
describe('LogWrapper', () => {
|
||||
describe('text logger torture test', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let data: any;
|
||||
const global = new GlobalLogger();
|
||||
global.configureLogging({
|
||||
json: false,
|
||||
level: 'debug',
|
||||
}, new Writable({
|
||||
write(chunk, _encoding, callback) {
|
||||
data = chunk.toString();
|
||||
callback();
|
||||
},
|
||||
}));
|
||||
|
||||
const log = new LogWrapper(MODULE_NAME, global);
|
||||
for (const args of tortureArgs) {
|
||||
it(`handles logging '${args.map(t => typeof t).join(', ')}'`, () => {
|
||||
for (const level of ['debug', 'info', 'warn', 'error']) {
|
||||
log[level as 'debug'|'info'|'warn'|'error'](args[0], ...args.slice(1));
|
||||
expect(data).to.include(level.toUpperCase());
|
||||
expect(data).to.include(MODULE_NAME);
|
||||
expect(data).to.not.be.undefined;
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
describe('JSON logger torture test', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let data: any;
|
||||
const global = new GlobalLogger();
|
||||
global.configureLogging({
|
||||
json: true,
|
||||
level: 'debug',
|
||||
}, new Writable({
|
||||
write(chunk, _encoding, callback) {
|
||||
data = JSON.parse(chunk.toString());
|
||||
callback();
|
||||
},
|
||||
}));
|
||||
|
||||
const log = new LogWrapper(MODULE_NAME, global);
|
||||
for (const args of tortureArgs) {
|
||||
it(`handles logging '${args.map(t => typeof t).join(', ')}'`, () => {
|
||||
for (const level of ['debug', 'info', 'warn', 'error']) {
|
||||
log[level as 'debug'|'info'|'warn'|'error'](args[0], ...args.slice(1));
|
||||
expect(data.level).to.equal(level.toUpperCase());
|
||||
expect(data.module).to.equal(MODULE_NAME);
|
||||
expect(data.message).to.not.be.undefined;
|
||||
expect(data.timestamp).to.not.be.undefined;
|
||||
if (args.length > 1) {
|
||||
expect(data.args).to.have.lengthOf(args.length-1);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
@ -1,3 +1,2 @@
|
||||
import LogWrapper from "../src/LogWrapper";
|
||||
|
||||
LogWrapper.root.configureLogging({level: "info"});
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
Logger.configure({console: "info"});
|
||||
|
46
yarn.lock
46
yarn.lock
@ -1165,6 +1165,16 @@
|
||||
"@types/qs" "*"
|
||||
"@types/serve-static" "*"
|
||||
|
||||
"@types/express@^4.17.14":
|
||||
version "4.17.14"
|
||||
resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.14.tgz#143ea0557249bc1b3b54f15db4c81c3d4eb3569c"
|
||||
integrity sha512-TEbt+vaPFQ+xpxFLFssxUDXj5cWCxZJjIcB7Yg0k0GMHGtgtQgpvx/MUQUeAkNbA9AAGrwkAsoeItdTgS7FMyg==
|
||||
dependencies:
|
||||
"@types/body-parser" "*"
|
||||
"@types/express-serve-static-core" "^4.17.18"
|
||||
"@types/qs" "*"
|
||||
"@types/serve-static" "*"
|
||||
|
||||
"@types/jira-client@^7.1.0":
|
||||
version "7.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/jira-client/-/jira-client-7.1.1.tgz#3010d69cc97831a98bf70830b249db63a45a3ff6"
|
||||
@ -1245,6 +1255,13 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.56.tgz#dcbb617669481e158e0f1c6204d1c768cd675901"
|
||||
integrity sha512-aFcUkv7EddxxOa/9f74DINReQ/celqH8DiB3fRYgVDM2Xm5QJL8sl80QKuAnGvwAsMn+H3IFA6WCrQh1CY7m1A==
|
||||
|
||||
"@types/pkginfo@^0.4.0":
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/pkginfo/-/pkginfo-0.4.0.tgz#00143b97e98aa7c9391943266d2e4aebd8f44c35"
|
||||
integrity sha512-4DGKkOlWkMuVDZQvytWzzWWAjyqDmlLKRYE4lzeA8t0s7fK0aF25uPbX9eBVermUjLJdeLHu9k1WmNiAssqCcg==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/qs@*":
|
||||
version "6.9.7"
|
||||
resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.7.tgz#63bb7d067db107cc1e457c303bc25d511febf6cb"
|
||||
@ -4227,12 +4244,13 @@ markdown-it@^12.3.2:
|
||||
mdurl "^1.0.1"
|
||||
uc.micro "^1.0.5"
|
||||
|
||||
matrix-appservice-bridge@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/matrix-appservice-bridge/-/matrix-appservice-bridge-5.0.0.tgz#e3b42f9c1bef9c2a5fe51c47e2232ea3040852d0"
|
||||
integrity sha512-d+F2RN/6o4TtBHOgcNECXX/UGjqM4zuWK14hmnzHHdrQi/Xuq9GSO14jMKsl1Jc0Kbkpv9cFMfhy27yo/Ju7/w==
|
||||
matrix-appservice-bridge@^6.0.0:
|
||||
version "6.0.0"
|
||||
resolved "https://registry.yarnpkg.com/matrix-appservice-bridge/-/matrix-appservice-bridge-6.0.0.tgz#ef091aceac8e24f7fd4c4e57676b2e028692d8de"
|
||||
integrity sha512-fUQhTw9xGZk2uwrTejpdmYjmm2Myp1VTKWfdLtHs3M5YHOwPTh9rA9UmWQcS5DOKFiqD4r1kiNl6jgu0/I5vTg==
|
||||
dependencies:
|
||||
"@alloc/quick-lru" "^5.2.0"
|
||||
"@types/pkginfo" "^0.4.0"
|
||||
axios "^0.27.2"
|
||||
chalk "^4.1.0"
|
||||
express "^4.18.1"
|
||||
@ -4241,17 +4259,18 @@ matrix-appservice-bridge@^5.0.0:
|
||||
ip-cidr "^3.0.4"
|
||||
is-my-json-valid "^2.20.5"
|
||||
js-yaml "^4.0.0"
|
||||
matrix-appservice "^1.0.0"
|
||||
matrix-bot-sdk "^0.6.1"
|
||||
matrix-appservice "^1.1.0"
|
||||
matrix-bot-sdk "^0.6.2"
|
||||
nedb "^1.8.0"
|
||||
nopt "^5.0.0"
|
||||
p-queue "^6.6.2"
|
||||
pkginfo "^0.4.1"
|
||||
prom-client "^14.0.0"
|
||||
uuid "^8.3.2"
|
||||
winston "^3.3.3"
|
||||
winston-daily-rotate-file "^4.5.1"
|
||||
|
||||
matrix-appservice@^1.0.0:
|
||||
matrix-appservice@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/matrix-appservice/-/matrix-appservice-1.1.0.tgz#e567945042000485e4ea4bfeef92246e93296f01"
|
||||
integrity sha512-6hJdmo9YIbh6dS9MfMHCpHMhklN/+NOcfGQ/3UbbEEfIE8dt0bHqi1nnIiias5IqDFl6ED9y+YQdtyqnIXx+Ww==
|
||||
@ -4262,10 +4281,10 @@ matrix-appservice@^1.0.0:
|
||||
js-yaml "^4.1.0"
|
||||
morgan "^1.10.0"
|
||||
|
||||
matrix-bot-sdk@^0.6.1:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/matrix-bot-sdk/-/matrix-bot-sdk-0.6.1.tgz#29c5d92fd6bc2eb0f6be2540ed133d8ffadaed93"
|
||||
integrity sha512-xbSQUpbuQq9Oj5f5GeprKndJZqdB9N9majg+VwIEcBGBscpWCskX32kTaoNhTHAE92XlM+qnwFME45TYElf4tA==
|
||||
matrix-bot-sdk@^0.6.2:
|
||||
version "0.6.2"
|
||||
resolved "https://registry.yarnpkg.com/matrix-bot-sdk/-/matrix-bot-sdk-0.6.2.tgz#c9334b39f62a9742d74e46312def566429dfef26"
|
||||
integrity sha512-+kXlXkQBQgWC6oUwYEosJlXjceaj7jQUnPlALFhGeAabgVm8tmuvFNVKqClwvrrjj+0Gzsmt+rcJHmkvqymFXA==
|
||||
dependencies:
|
||||
"@matrix-org/matrix-sdk-crypto-nodejs" "^0.1.0-beta.1"
|
||||
"@types/express" "^4.17.13"
|
||||
@ -4889,6 +4908,11 @@ pkg-dir@^4.1.0:
|
||||
dependencies:
|
||||
find-up "^4.0.0"
|
||||
|
||||
pkginfo@^0.4.1:
|
||||
version "0.4.1"
|
||||
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.4.1.tgz#b5418ef0439de5425fc4995042dced14fb2a84ff"
|
||||
integrity sha512-8xCNE/aT/EXKenuMDZ+xTVwkT8gsoHN2z/Q29l80u0ppGEXVvsKRzNMbtKhg8LS8k1tJLAHHylf6p4VFmP6XUQ==
|
||||
|
||||
postcss@^8.1.10:
|
||||
version "8.4.16"
|
||||
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.16.tgz#33a1d675fac39941f5f445db0de4db2b6e01d43c"
|
||||
|
Loading…
x
Reference in New Issue
Block a user