Commit 5633a039 authored by nanahira's avatar nanahira

improve

parent 09535e3e
Pipeline #6106 failed with stages
in 30 seconds
{ {
"name": "koishi-nestjs", "name": "koishi-nestjs",
"version": "1.0.16", "version": "1.0.18",
"description": "Koishi.js as Nest.js Module", "description": "Koishi.js as Nest.js Module",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
......
import { import { ConsoleLogger, Inject, Injectable } from '@nestjs/common';
ConsoleLogger,
Inject,
Injectable,
OnModuleInit,
} from '@nestjs/common';
import { Logger } from 'koishi'; import { Logger } from 'koishi';
import { KOISHI_MODULE_OPTIONS } from './koishi.constants'; import { KOISHI_MODULE_OPTIONS } from './koishi.constants';
import { KoishiModuleOptions } from './koishi.interfaces'; import { KoishiModuleOptions } from './koishi.interfaces';
...@@ -17,29 +12,31 @@ export class KoishiLoggerService extends ConsoleLogger { ...@@ -17,29 +12,31 @@ export class KoishiLoggerService extends ConsoleLogger {
Logger.targets = [ Logger.targets = [
{ {
colors: 3, colors: 3,
print(text: string) { print: (text: string) => this.printKoishiLog(text),
const header = text.slice(0, 4);
const body = text.slice(4);
switch (header) {
case '[S] ':
case '[I] ':
_this.log(body);
break;
case '[W] ':
_this.warn(body);
break;
case '[E] ':
_this.error(body);
break;
case '[D] ':
_this.debug(body);
break;
default:
_this.log(text);
break;
}
},
}, },
]; ];
} }
private printKoishiLog(text: string) {
const header = text.slice(0, 4);
const body = text.slice(4);
switch (header) {
case '[S] ':
case '[I] ':
this.log(body);
break;
case '[W] ':
this.warn(body);
break;
case '[E] ':
this.error(body);
break;
case '[D] ':
this.debug(body);
break;
default:
this.log(text);
break;
}
}
} }
import { App, Logger } from 'koishi'; import { App } from 'koishi';
import { import {
ConsoleLogger, ConsoleLogger,
Inject, Inject,
......
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