Commit 85d4c653 authored by nanahira's avatar nanahira

add @InjectLogger

parent 2fba1157
......@@ -61,6 +61,8 @@ koishi-thirdeye 内建了对[`koishi-utils-schemagen`](https://github.com/koishi
* `@InjectApp()` 注入 Koishi 实例对象。
* `@InjectLogger(name: string)` 注入 Koishi 日志记录器。
### 声明周期钩子
下列方法是一些生命周期方法。这些方法会在插件特定生命周期中调用,便于注册方法等操作。
......
......@@ -222,3 +222,7 @@ export const InjectContext = (select?: Selection) =>
export const InjectApp = () => InjectSystem((obj) => obj.__ctx.app);
export const InjectConfig = (raw = false) =>
InjectSystem((obj) => (raw ? obj.__rawConfig : obj.__config));
export const InjectLogger = (name?: string) =>
InjectSystem((obj) =>
obj.__ctx.logger(name || obj.__pluginOptions?.name || 'default'),
);
......@@ -28,6 +28,7 @@ export interface PluginClass<T = any> {
__ctx: Context;
__config: T;
__rawConfig: T;
__pluginOptions: KoishiPluginRegistrationOptions<T>;
}
export interface OnApply {
......@@ -58,6 +59,7 @@ export function KoishiPlugin<T = any>(
__ctx: Context;
__config: T;
__rawConfig: T;
__pluginOptions: KoishiPluginRegistrationOptions<T>;
_handleSystemInjections() {
// console.log('Handling system injection');
......@@ -322,6 +324,7 @@ export function KoishiPlugin<T = any>(
this.__ctx = ctx;
this.__rawConfig = rawConfig;
this.__config = config;
this.__pluginOptions = options;
this._initializePluginClass().then();
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment