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

View File

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