From 1ea70be80cb95469b84b57790424f4b10fb45cb7 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 10 Sep 2020 14:50:13 +0200 Subject: [PATCH] set ocen-lib-js log levels based on debug value --- src/components/atoms/FormikPersist.tsx | 7 ++++--- src/providers/UserPreferences.tsx | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/atoms/FormikPersist.tsx b/src/components/atoms/FormikPersist.tsx index cebf469a1..d51eb8f0e 100644 --- a/src/components/atoms/FormikPersist.tsx +++ b/src/components/atoms/FormikPersist.tsx @@ -3,6 +3,7 @@ import { FormikProps, connect } from 'formik' import debounce from 'lodash.debounce' import omit from 'lodash.omit' import isEqual from 'react-fast-compare' +import { Logger } from '@oceanprotocol/lib' export interface PersistProps { name: string @@ -21,7 +22,7 @@ class PersistImpl extends React.Component< saveForm = debounce((data: FormikProps) => { const dataToSave = this.omitIgnoredFields(data) - console.log('data tosave', dataToSave) + Logger.log('data to save', dataToSave) if (this.props.isSessionStorage) { window.sessionStorage.setItem(this.props.name, JSON.stringify(dataToSave)) } else { @@ -31,10 +32,10 @@ class PersistImpl extends React.Component< omitIgnoredFields = (data: FormikProps) => { const { ignoreFields } = this.props - console.log('omit fiel', ignoreFields) + Logger.log('omitted fields', ignoreFields) const { values, touched, errors } = data - console.log('vale', values, omit(values, ignoreFields)) + Logger.log('values', values, omit(values, ignoreFields)) return ignoreFields ? omit( { diff --git a/src/providers/UserPreferences.tsx b/src/providers/UserPreferences.tsx index 09f1399bc..52deca853 100644 --- a/src/providers/UserPreferences.tsx +++ b/src/providers/UserPreferences.tsx @@ -6,6 +6,8 @@ import React, { useState, useEffect } from 'react' +import { Logger } from '@oceanprotocol/lib' +import { LogLevel } from '@oceanprotocol/lib/dist/node/utils/Logger' interface UserPreferencesValue { debug: boolean @@ -52,6 +54,13 @@ function UserPreferencesProvider({ setLocalStorage({ debug, currency }) }, [debug, currency]) + // Set ocen-lib-js log levels, default: Error + useEffect(() => { + debug === true + ? Logger.setLevel(LogLevel.Verbose) + : Logger.setLevel(LogLevel.Error) + }, [debug]) + return (