fix(log): make setup and destroy sync (#2532)

Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
This commit is contained in:
Leo Kettmeir 2022-09-08 09:21:26 +01:00 committed by GitHub
parent e4badb0aa8
commit ebeecacd61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View File

@ -50,8 +50,8 @@ export class BaseHandler {
}
log(_msg: string) {}
async setup() {}
async destroy() {}
setup() {}
destroy() {}
}
export class ConsoleHandler extends BaseHandler {
@ -120,8 +120,8 @@ export class FileHandler extends WriterHandler {
};
}
override async setup() {
this._file = await Deno.open(this._filename, this._openOptions);
override setup() {
this._file = Deno.openSync(this._filename, this._openOptions);
this._writer = this._file;
this._buf = new BufWriterSync(this._file);
@ -155,7 +155,6 @@ export class FileHandler extends WriterHandler {
this._file?.close();
this._file = undefined;
removeEventListener("unload", this.#unloadCallback);
return Promise.resolve();
}
}

View File

@ -172,7 +172,7 @@ export function critical<T>(
}
/** Setup logger config. */
export async function setup(config: LogConfig) {
export function setup(config: LogConfig) {
state.config = {
handlers: { ...DEFAULT_CONFIG.handlers, ...config.handlers },
loggers: { ...DEFAULT_CONFIG.loggers, ...config.loggers },
@ -189,7 +189,7 @@ export async function setup(config: LogConfig) {
for (const handlerName in handlers) {
const handler = handlers[handlerName];
await handler.setup();
handler.setup();
state.handlers.set(handlerName, handler);
}
@ -216,4 +216,4 @@ export async function setup(config: LogConfig) {
}
}
await setup(DEFAULT_CONFIG);
setup(DEFAULT_CONFIG);