mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
* [Typescript/Chore] Convert LevelLogger to Typescript * prettier * tags optional for warn * fix shadow lint rule
This commit is contained in:
parent
438bfa49ae
commit
7bee8eaab8
2 changed files with 52 additions and 42 deletions
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
|
||||
export class LevelLogger {
|
||||
|
||||
static createForServer(server, tags) {
|
||||
return new LevelLogger(
|
||||
(tags, msg) => server.log(tags, msg),
|
||||
tags,
|
||||
server.config().get('logging.verbose'));
|
||||
}
|
||||
|
||||
constructor(logger, tags, isVerbose) {
|
||||
this._logger = logger;
|
||||
this._tags = tags;
|
||||
this.isVerbose = isVerbose;
|
||||
}
|
||||
|
||||
error(msg, tags = []) {
|
||||
this._logger([...this._tags, ...tags, 'error'], msg);
|
||||
}
|
||||
|
||||
warning(msg, tags = []) {
|
||||
this._logger([...this._tags, ...tags, 'warning'], msg);
|
||||
}
|
||||
|
||||
debug(msg, tags = []) {
|
||||
this._logger([...this._tags, ...tags, 'debug'], msg);
|
||||
}
|
||||
|
||||
info(msg, tags = []) {
|
||||
this._logger([...this._tags, ...tags, 'info'], msg);
|
||||
}
|
||||
|
||||
clone(tags) {
|
||||
return new LevelLogger(this._logger, [...this._tags, ...tags], this.isVerbose);
|
||||
}
|
||||
}
|
52
x-pack/plugins/reporting/server/lib/level_logger.ts
Normal file
52
x-pack/plugins/reporting/server/lib/level_logger.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { Logger } from '../../types';
|
||||
|
||||
type ServerLog = (tags: string[], msg: string) => void;
|
||||
|
||||
export class LevelLogger implements Logger {
|
||||
private _logger: any;
|
||||
private _tags: string[];
|
||||
|
||||
public warn: (msg: string, tags?: string[]) => void;
|
||||
|
||||
static createForServer(server: any, tags: string[]) {
|
||||
const serverLog: ServerLog = (tgs: string[], msg: string) => server.log(tgs, msg);
|
||||
return new LevelLogger(serverLog, tags);
|
||||
}
|
||||
|
||||
constructor(logger: ServerLog, tags: string[]) {
|
||||
this._logger = logger;
|
||||
this._tags = tags;
|
||||
|
||||
/*
|
||||
* This shortcut provides maintenance convenience: Reporting code has been
|
||||
* using both .warn and .warning
|
||||
*/
|
||||
this.warn = this.warning.bind(this);
|
||||
}
|
||||
|
||||
public error(msg: string, tags: string[] = []) {
|
||||
this._logger([...this._tags, ...tags, 'error'], msg);
|
||||
}
|
||||
|
||||
public warning(msg: string, tags: string[] = []) {
|
||||
this._logger([...this._tags, ...tags, 'warning'], msg);
|
||||
}
|
||||
|
||||
public debug(msg: string, tags: string[] = []) {
|
||||
this._logger([...this._tags, ...tags, 'debug'], msg);
|
||||
}
|
||||
|
||||
public info(msg: string, tags: string[] = []) {
|
||||
this._logger([...this._tags, ...tags, 'info'], msg);
|
||||
}
|
||||
|
||||
public clone(tags: string[]) {
|
||||
return new LevelLogger(this._logger, [...this._tags, ...tags]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue