1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 09:44:53 +01:00

set ocen-lib-js log levels based on debug value

This commit is contained in:
Matthias Kretschmann 2020-09-10 14:50:13 +02:00
parent a8d8c95acb
commit 1ea70be80c
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 13 additions and 3 deletions

View File

@ -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<any>) => {
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<any>) => {
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(
{

View File

@ -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 (
<UserPreferencesContext.Provider
value={{ debug, currency, setDebug, setCurrency } as UserPreferencesValue}