1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

set default logger level to error and use only one instance of logger (#571)

This commit is contained in:
Bogdan Fazakas 2021-02-02 14:53:16 +02:00 committed by GitHub
parent c3b947c51a
commit 6e3173f697
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 18 deletions

View File

@ -1,6 +1,6 @@
import Web3 from 'web3' import Web3 from 'web3'
import Config from './models/Config' import Config from './models/Config'
import { Logger, LoggerInstance, LogLevel } from './utils' import { Logger, LoggerInstance } from './utils'
import { Ocean } from './ocean/Ocean' import { Ocean } from './ocean/Ocean'
export interface InstantiableConfig { export interface InstantiableConfig {
@ -13,48 +13,37 @@ export interface InstantiableConfig {
export function generateIntantiableConfigFromConfig( export function generateIntantiableConfigFromConfig(
config: Config config: Config
): Partial<InstantiableConfig> { ): Partial<InstantiableConfig> {
const logLevel =
typeof config.verbose !== 'number'
? config.verbose
? LogLevel.Log
: LogLevel.None
: (config.verbose as LogLevel)
return { return {
config, config,
web3: config.web3Provider, web3: config.web3Provider,
logger: new Logger(logLevel) logger: LoggerInstance
} }
} }
export abstract class Instantiable { export abstract class Instantiable {
protected get ocean(): Ocean { protected get ocean(): Ocean {
if (!this._ocean) { if (!this._ocean) {
this.logger.error('Ocean instance is not defined.') LoggerInstance.error('Ocean instance is not defined.')
} }
return this._ocean return this._ocean
} }
protected get web3(): Web3 { protected get web3(): Web3 {
if (!this._web3) { if (!this._web3) {
this.logger.error('Web3 instance is not defined.') LoggerInstance.error('Web3 instance is not defined.')
} }
return this._web3 return this._web3
} }
protected get config(): Config { protected get config(): Config {
if (!this._config) { if (!this._config) {
this.logger.error('Config instance is not defined.') LoggerInstance.error('Config instance is not defined.')
} }
return this._config return this._config
} }
protected get logger(): Logger { protected get logger(): Logger {
if (!this._logger) { return LoggerInstance
LoggerInstance.error('Logger instance is not defined.')
LoggerInstance.error('Using default instance.')
return LoggerInstance
}
return this._logger
} }
protected get instanceConfig(): InstantiableConfig { protected get instanceConfig(): InstantiableConfig {

View File

@ -7,7 +7,7 @@ export enum LogLevel {
} }
export class Logger { export class Logger {
constructor(private logLevel: LogLevel = LogLevel.Verbose) {} constructor(private logLevel: LogLevel = LogLevel.Error) {}
public setLevel(logLevel: LogLevel): void { public setLevel(logLevel: LogLevel): void {
this.logLevel = logLevel this.logLevel = logLevel