Ethers.js: Unable to set log level

Created on 13 Jul 2020  路  4Comments  路  Source: ethers-io/ethers.js

Hello, thank you for your work on ethers.js. I'm trying to set the log level on [email protected]:

import { ethers } from 'ethers'

ethers.utils.Logger.setLogLevel(ethers.utils.Logger.levels.OFF)

But that does not appear to work. Instead, it outputs:

invalid log level - OFF

What's the right way to set the log level? I've looked at https://github.com/ethers-io/ethers.js/issues/379, but the API seems to have changed.

bug fixed

All 4 comments

It looks like I have a case mismatch in the enum compared to the lookup table.

Can you try using the string "off" instead of the enum? I鈥檒l fix this tomorrow.

@ricmoo

Doing this:

ethers.utils.Logger.setLogLevel('off')

Should work in plain JS, since:

// https://github.com/ethers-io/ethers.js/blob/master/packages/logger/lib/index.js#L5
var LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };

Unfortunately, in a Typescript project this raises an error:

Argument of type '"off"' is not assignable to parameter of type 'LogLevel'

This should be fixed in v5.0.7.

Try it out and let me know if it works for you. :)

@ricmoo It works, thank you!

Was this page helpful?
0 / 5 - 0 ratings