mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Configure and use matrix-appservice-bridge's Logger
https://github.com/matrix-org/mjolnir/issues/422 Haven't changed all of the mjolnir components to use this, just the appservice. The fact that we've configured this properly means we get logging from matrix-appservice-bridge components too (we didn't before).
This commit is contained in:
parent
193d0826c5
commit
da36668a44
@ -3,7 +3,9 @@ import express from "express";
|
||||
import * as bodyParser from "body-parser";
|
||||
import { MjolnirManager } from "./MjolnirManager";
|
||||
import * as http from "http";
|
||||
import { Logger } from "matrix-appservice-bridge";
|
||||
|
||||
const log = new Logger("Api");
|
||||
/**
|
||||
* This provides a web api that is designed to power the mjolnir widget https://github.com/matrix-org/mjolnir-widget.
|
||||
*/
|
||||
@ -28,7 +30,7 @@ export class Api {
|
||||
qs: { access_token: accessToken },
|
||||
}, (err, homeserver_response, body) => {
|
||||
if (err) {
|
||||
console.error(`Error resolving openID token from ${this.homeserver}`, err);
|
||||
log.error(`Error resolving openID token from ${this.homeserver}`, err);
|
||||
reject(null);
|
||||
}
|
||||
|
||||
@ -36,7 +38,7 @@ export class Api {
|
||||
try {
|
||||
response = JSON.parse(body);
|
||||
} catch (e) {
|
||||
console.error(`Received ill formed response from ${this.homeserver} when resolving an openID token`, e);
|
||||
log.error(`Received ill formed response from ${this.homeserver} when resolving an openID token`, e);
|
||||
reject(null);
|
||||
return;
|
||||
}
|
||||
|
@ -14,13 +14,14 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { AppServiceRegistration, Bridge, Request, WeakEvent, BridgeContext, MatrixUser } from "matrix-appservice-bridge";
|
||||
import { AppServiceRegistration, Bridge, Request, WeakEvent, BridgeContext, MatrixUser, Logger } from "matrix-appservice-bridge";
|
||||
import { MjolnirManager } from ".//MjolnirManager";
|
||||
import { DataStore, PgDataStore } from ".//datastore";
|
||||
import { Api } from "./Api";
|
||||
import { IConfig } from "./config/config";
|
||||
import { AccessControl } from "./AccessControl";
|
||||
|
||||
const log = new Logger("AppService");
|
||||
/**
|
||||
* Responsible for setting up listeners and delegating functionality to a matrix-appservice-bridge `Bridge` for
|
||||
* the entrypoint of the application.
|
||||
@ -89,6 +90,7 @@ export class MjolnirAppService {
|
||||
* @param registrationFilePath A path to their homeserver registration file.
|
||||
*/
|
||||
public static async run(port: number, config: IConfig, registrationFilePath: string): Promise<MjolnirAppService> {
|
||||
Logger.configure(config.logging ?? { console: "debug" });
|
||||
const dataStore = new PgDataStore(config.db.connectionString);
|
||||
await dataStore.init();
|
||||
const service = await MjolnirAppService.makeMjolnirAppService(config, dataStore, registrationFilePath);
|
||||
@ -114,10 +116,12 @@ export class MjolnirAppService {
|
||||
// Acts as an alternative to the web api provided for the widget.
|
||||
if ('m.room.member' === mxEvent.type) {
|
||||
if ('invite' === mxEvent.content['membership'] && mxEvent.state_key === this.bridge.botUserId) {
|
||||
await this.mjolnirManager.provisionNewMjolnir(mxEvent.sender);
|
||||
await this.mjolnirManager.provisionNewMjolnir(mxEvent.sender).catch((e: any) => {
|
||||
log.error(`Failed to provision a mjolnir for ${mxEvent.sender} after they invited ${this.bridge.botUserId}:`, e);
|
||||
});
|
||||
// reject the invite to keep the room clean and make sure the invetee doesn't get confused and think this is their mjolnir.
|
||||
this.bridge.getBot().getClient().leaveRoom(mxEvent.room_id).catch(e => {
|
||||
console.warn("Unable to reject an invite to a room", e)
|
||||
log.warn("Unable to reject an invite to a room", e);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -130,10 +134,10 @@ export class MjolnirAppService {
|
||||
* @param port The port that the appservice should listen on to receive transactions from the homeserver.
|
||||
*/
|
||||
private async start(port: number) {
|
||||
console.log("Starting MjolnirAppService, Matrix-side to listen on port %s", port);
|
||||
log.info("Starting MjolnirAppService, Matrix-side to listen on port", port);
|
||||
this.api.start(this.config.webAPI.port);
|
||||
await this.bridge.listen(port);
|
||||
console.log("MjolnirAppService started successfully");
|
||||
log.info("MjolnirAppService started successfully");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ limitations under the License.
|
||||
|
||||
import * as fs from "fs";
|
||||
import { load } from "js-yaml";
|
||||
import { LoggingOpts } from "matrix-appservice-bridge";
|
||||
|
||||
export interface IConfig {
|
||||
/** Details for the homeserver the appservice will be serving */
|
||||
@ -36,6 +37,8 @@ export interface IConfig {
|
||||
},
|
||||
/** A policy room for controlling access to the appservice */
|
||||
accessControlList: string,
|
||||
/** configuration for matrix-appservice-bridge's Logger */
|
||||
logging?: LoggingOpts,
|
||||
}
|
||||
|
||||
export function read(configPath: string): IConfig {
|
||||
|
Loading…
Reference in New Issue
Block a user