Expose logger through ExtensionContext (#7777)

Fixes #7737.
This commit is contained in:
Dieter Luypaert
2021-09-02 19:46:51 +02:00
committed by GitHub
parent 4f284e455e
commit da6f492a44
7 changed files with 11 additions and 2 deletions

View File

@@ -155,7 +155,7 @@ function registerHooks(hooks: Extension[]) {
const register = getModuleDefault(hookInstance);
const events = register({ services, exceptions, env, database: getDatabase(), getSchema });
const events = register({ services, exceptions, env, database: getDatabase(), logger, getSchema });
for (const [event, handler] of Object.entries(events)) {
if (event.startsWith('cron(')) {
@@ -195,6 +195,6 @@ function registerEndpoints(endpoints: Extension[], router: Router) {
const scopedRouter = express.Router();
router.use(`/${pathName}`, scopedRouter);
register(scopedRouter, { services, exceptions, env, database: getDatabase(), getSchema });
register(scopedRouter, { services, exceptions, env, database: getDatabase(), logger, getSchema });
}
}

View File

@@ -1,6 +1,7 @@
import { ListenerFn } from 'eventemitter2';
import { Router } from 'express';
import { Knex } from 'knex';
import { Logger } from 'pino';
import env from '../env';
import * as exceptions from '../exceptions';
import * as services from '../services';
@@ -11,6 +12,7 @@ export type ExtensionContext = {
exceptions: typeof exceptions;
database: Knex;
env: typeof env;
logger: Logger;
getSchema: typeof getSchema;
};

View File

@@ -40,6 +40,7 @@ that is scoped to `/<extension-name>`, while `context` holds the following prope
- `database` — Knex instance that is connected to the current database.
- `getSchema` — Async function that reads the full available schema for use in services
- `env` Parsed environment variables.
- `logger` — [Pino](https://github.com/pinojs/pino) instance.
## 3. Restart the API

View File

@@ -155,6 +155,7 @@ The `registerHook` function receives a context parameter with the following prop
- `database` — Knex instance that is connected to the current database
- `getSchema` — Async function that reads the full available schema for use in services
- `env` Parsed environment variables
- `logger` — [Pino](https://github.com/pinojs/pino) instance.
### Event Handler Function

2
package-lock.json generated
View File

@@ -51264,6 +51264,7 @@
"knex": "0.95.10",
"knex-schema-inspector": "1.6.0",
"lodash": "4.17.21",
"pino": "6.13.1",
"vue": "3.2.7",
"vue-router": "4.0.11"
},
@@ -53405,6 +53406,7 @@
"knex-schema-inspector": "1.6.0",
"lodash": "4.17.21",
"npm-run-all": "4.1.5",
"pino": "6.13.1",
"rimraf": "3.0.2",
"typescript": "4.4.2",
"vue": "3.2.7",

View File

@@ -54,6 +54,7 @@
"knex": "0.95.10",
"knex-schema-inspector": "1.6.0",
"lodash": "4.17.21",
"pino": "6.13.1",
"vue": "3.2.7",
"vue-router": "4.0.11"
},

View File

@@ -1,4 +1,5 @@
import { Knex } from 'knex';
import { Logger } from 'pino';
import {
API_EXTENSION_PACKAGE_TYPES,
API_EXTENSION_TYPES,
@@ -65,5 +66,6 @@ export type ApiExtensionContext = {
exceptions: any;
database: Knex;
env: Record<string, any>;
logger: Logger;
getSchema: (options?: { accountability?: Accountability; database?: Knex }) => Promise<Record<string, any>>;
};