Split out logging a bit, fix accept header parsing

This commit is contained in:
Bryan Ashby 2023-04-25 11:46:19 -06:00
parent 31f10d0c78
commit a5a72d8270
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
6 changed files with 26 additions and 22 deletions

View File

@ -30,7 +30,7 @@ module.exports = class Log {
const serializers = Log.standardSerializers(); const serializers = Log.standardSerializers();
this.log = bunyan.createLogger({ this.log = bunyan.createLogger({
name: 'ENiGMA½ BBS', name: 'ENiGMA½',
streams: logStreams, streams: logStreams,
serializers: serializers, serializers: serializers,
}); });

View File

@ -1,5 +1,5 @@
// ENiGMA½ // ENiGMA½
const Log = require('../../logger.js').log; const SysLog = require('../../logger.js').log;
const ServerModule = require('../../server_module.js').ServerModule; const ServerModule = require('../../server_module.js').ServerModule;
const Config = require('../../config.js').get; const Config = require('../../config.js').get;
const { Errors } = require('../../enig_error.js'); const { Errors } = require('../../enig_error.js');
@ -75,7 +75,6 @@ exports.getModule = class WebServerModule extends ServerModule {
constructor() { constructor() {
super(); super();
//this.log = Log.child({ server: 'Web' });
this.log = WebLog.createWebLog(); this.log = WebLog.createWebLog();
const config = Config(); const config = Config();
@ -133,14 +132,14 @@ exports.getModule = class WebServerModule extends ServerModule {
try { try {
const normalizedName = _.camelCase(module.moduleInfo.name); const normalizedName = _.camelCase(module.moduleInfo.name);
if (!WebHandlerModule.isEnabled(normalizedName)) { if (!WebHandlerModule.isEnabled(normalizedName)) {
this.log.info( SysLog.info(
{ moduleName: normalizedName }, { moduleName: normalizedName },
'Web handler module not enabled' 'Web handler module not enabled'
); );
return nextModule(null); return nextModule(null);
} }
Log.info( SysLog.info(
{ moduleName: normalizedName }, { moduleName: normalizedName },
'Initializing web handler module' 'Initializing web handler module'
); );
@ -149,7 +148,7 @@ exports.getModule = class WebServerModule extends ServerModule {
return nextModule(err); return nextModule(err);
}); });
} catch (e) { } catch (e) {
this.log.error( SysLog.error(
{ error: e.message }, { error: e.message },
'Exception caught loading web handler' 'Exception caught loading web handler'
); );
@ -171,7 +170,7 @@ exports.getModule = class WebServerModule extends ServerModule {
if (this[name]) { if (this[name]) {
const port = parseInt(config.contentServers.web[service].port); const port = parseInt(config.contentServers.web[service].port);
if (isNaN(port)) { if (isNaN(port)) {
this.log.error( SysLog.error(
{ {
port: config.contentServers.web[service].port, port: config.contentServers.web[service].port,
server: ModuleInfo.name, server: ModuleInfo.name,
@ -206,7 +205,7 @@ exports.getModule = class WebServerModule extends ServerModule {
route = new Route(route); route = new Route(route);
if (!route.isValid()) { if (!route.isValid()) {
this.log.error( SysLog.error(
{ route: route }, { route: route },
'Cannot add route: missing or invalid required members' 'Cannot add route: missing or invalid required members'
); );
@ -215,7 +214,7 @@ exports.getModule = class WebServerModule extends ServerModule {
const routeKey = route.getRouteKey(); const routeKey = route.getRouteKey();
if (routeKey in this.routes) { if (routeKey in this.routes) {
this.log.warn( SysLog.warn(
{ route: route, routeKey: routeKey }, { route: route, routeKey: routeKey },
'Cannot add route: duplicate method/path combination exists' 'Cannot add route: duplicate method/path combination exists'
); );

View File

@ -6,6 +6,7 @@ const {
getActorId, getActorId,
prepareLocalUserAsActor, prepareLocalUserAsActor,
} = require('../../../activitypub/util'); } = require('../../../activitypub/util');
const SysLog = require('../../../logger').log;
const { const {
ActivityStreamMediaType, ActivityStreamMediaType,
WellKnownActivity, WellKnownActivity,
@ -182,7 +183,8 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
} }
// Additionally, serve activity JSON if the proper 'Accept' header was sent // Additionally, serve activity JSON if the proper 'Accept' header was sent
const accept = req.headers['accept'].split(',').map(v => v.trim()) || ['*/*']; const accept = (req.headers.accept &&
req.headers.accept.split(',').map(v => v.trim())) || ['*/*'];
const headerValues = [ const headerValues = [
ActivityStreamMediaType, ActivityStreamMediaType,
'application/ld+json', 'application/ld+json',
@ -396,7 +398,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
_inboxAcceptFollowActivity(resp, activity) { _inboxAcceptFollowActivity(resp, activity) {
// Currently Accept's to Follow's are really just a formality; // Currently Accept's to Follow's are really just a formality;
// we'll log it, but that's about it for now // we'll log it, but that's about it for now
this.log.info( SysLog.info(
{ {
remoteActorId: activity.actor, remoteActorId: activity.actor,
localActorId: _.get(activity, 'object.actor'), localActorId: _.get(activity, 'object.actor'),
@ -626,7 +628,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
// :TODO: log me // :TODO: log me
} }
this.log.info({ stats, inboxType }, 'Inbox Delete request complete'); SysLog.info({ stats, inboxType }, 'Inbox Delete request complete');
return this.webServer.accepted(resp); return this.webServer.accepted(resp);
} }
); );
@ -802,7 +804,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
return this.webServer.internalServerError(resp, err); return this.webServer.internalServerError(resp, err);
} }
this.log.info( SysLog.info(
{ {
username: localUser.username, username: localUser.username,
userId: localUser.userId, userId: localUser.userId,
@ -906,7 +908,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
return this.webServer.internalServerError(resp, err); return this.webServer.internalServerError(resp, err);
} }
this.log.info( SysLog.info(
{ {
inboxType, inboxType,
objectId: targetObjectId, objectId: targetObjectId,
@ -926,7 +928,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
} }
_deliverNoteToSharedInbox(activity, note, cb) { _deliverNoteToSharedInbox(activity, note, cb) {
this.log.info( SysLog.info(
{ activityId: activity.id, noteId: note.id }, { activityId: activity.id, noteId: note.id },
'Delivering Note to Public/Shared inbox' 'Delivering Note to Public/Shared inbox'
); );
@ -957,9 +959,14 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
return cb(null); // not found/etc., just bail return cb(null); // not found/etc., just bail
} }
this.log.info( this.sysLog.info(
{ activityId: activity.id, noteId: note.id, actorId }, {
'Delivering Note to local Actor Private inbox' activityId: activity.id,
noteId: note.id,
actorId,
username: localUser.username,
},
`Delivering private Note to local Actor "${localUser.username}"`
); );
Collection.addInboxItem(activity, localUser, false, err => { Collection.addInboxItem(activity, localUser, false, err => {
@ -1209,7 +1216,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
} }
_prepareNewUserAsActor(user, cb) { _prepareNewUserAsActor(user, cb) {
this.log.info( this.sysLog.info(
{ username: user.username, userId: user.userId }, { username: user.username, userId: user.userId },
`Preparing ActivityPub settings for "${user.username}"` `Preparing ActivityPub settings for "${user.username}"`
); );

View File

@ -27,8 +27,6 @@ exports.getModule = class SystemGeneralWebHandler extends WebHandlerModule {
this.webServer = webServer; this.webServer = webServer;
EngiAssert(webServer, 'System General Web Handler init without webServer'); EngiAssert(webServer, 'System General Web Handler init without webServer');
this.log = webServer.logger().child({ webHandler: 'SysGeneral' });
const domain = getWebDomain(); const domain = getWebDomain();
if (!domain) { if (!domain) {
return cb(Errors.UnexpectedState('Web server does not have "domain" set')); return cb(Errors.UnexpectedState('Web server does not have "domain" set'));

View File

@ -19,7 +19,7 @@ module.exports = class WebLog {
serializers.res = bunyan.stdSerializers.res; serializers.res = bunyan.stdSerializers.res;
const webLog = bunyan.createLogger({ const webLog = bunyan.createLogger({
name: 'ENiGMA½ BBS[Web]', name: 'ENiGMA½',
streams: [rotatingFile], streams: [rotatingFile],
serializers, serializers,
}); });