ethers.js/docs.wrm/api/utils/logger.wrm

209 lines
7.4 KiB
Plaintext
Raw Normal View History

2020-02-25 22:57:11 +03:00
_section: Logging @<logging>
2020-02-18 01:56:13 +03:00
2020-02-25 22:57:11 +03:00
These are just a few simple logging utilities provided to simplify
and standardize the error facilities across the Ethers library.
2020-02-18 01:56:13 +03:00
2020-02-25 22:57:11 +03:00
The [[logger]] library has zero dependencies and is intentionally
very light so it can be easily included in each library.
2020-02-18 01:56:13 +03:00
2020-02-25 22:57:11 +03:00
The [Censorship](logger-censorship) functionality relies on one instance
of the Ethers library being included. In large bundled packages or when
``npm link`` is used, this may not be the case. If you require this
functionality, ensure that your bundling is configured properly.
2020-02-18 01:56:13 +03:00
2020-02-25 22:57:11 +03:00
_subsection: Logger @<logger> @SRC<logger:class.Logger>
2020-02-18 01:56:13 +03:00
2020-02-25 22:57:11 +03:00
_property: new ethers.utils.Logger(version) @SRC<logger:constructor.Logger>
Create a new logger which will include //version// in all errors thrown.
_property: Logger.globalLogger() => [[logger]] @SRC<logger>
Returns the singleton global logger.
_heading: Logging Output
_property: logger.debug(...args) => void @SRC<logger>
Log debugging information.
_property: logger.info(...args) => void @SRC<logger>
Log generic information.
_property: logger.warn(...args) => void @SRC<logger>
Log warnings.
_heading: Errors
These functions honor the current [Censorship](logger-censorship) and help create
a standard error model for detecting and processing errors within Ethers.
_property: logger.makeError(message [ , code = UNKNOWN_ERROR [ , params ] ]) => Error @SRC<logger>
Create an Error object with //message// and an optional //code// and
additional //params// set. This is useful when an error is needed to be
rejected instead of thrown.
_property: logger.throwError(message [ , code = UNKNOWN_ERROR [ , params ] ]) => never @SRC<logger>
Throw an Error with //message// and an optional //code// and
additional //params// set.
_property: logger.throwArgumentError(message, name, value) => never @SRC<logger>
Throw an [INVALID_ARGUMENT](error-invalidargument) Error with //name// and //value//.
_heading: Usage Validation
There can be used to ensure various properties and actions are safe.
_property: logger.checkAbstract(target, kind) => void @SRC<logger>
Checks that //target// is not //kind// and performs the same operatons
as ``checkNew``. This is useful for ensuring abstract classes are not
being instantiated.
_property: logger.checkArgumentCount(count, expectedCound [ , message) => void @SRC<logger>
If //count// is not equal to //expectedCount//, throws a [MISSING_ARGUMENT](error-missingargument)
or [UNEXPECTED_ARGUMENT](error-unexpectedargument) error.
_property: logger.checkNew(target, kind) => void @SRC<logger>
If //target// is not a valid ``this`` or ``target`` value, throw a
[MISSING_NEW](error-missingnew) error. This is useful to ensure
callers of a Class are using ``new``.
_property: logger.checkNormalize(message) => void @SRC<logger>
Check that the environment has a correctly functioning [[link-js-normalize]]. If not, a
[UNSUPPORTED_OPERATION](error-unsupported) error is thrown.
_property: logger.checkSafeUint53(value [, message ]) => void @SRC<logger>
If //value// is not safe as a [JavaScript number](link-wiki-ieee754), throws a
[NUMERIC_FAULT](error-numericfault) error.
_heading: Censorship @<logger-censorship>
_property: Logger.setCensorship(censor [ , permanent = false ]) => void @SRC<logger>
Set error censorship, optionally preventing errors from being uncensored.
In production applications, this prevents any error from leaking information
by masking the message and values of errors.
This can impact debugging, making it substantially more difficult.
_property: Logger.setLogLevel(logLevel) => void @SRC<logger>
Set the log level, to suppress logging output below a [particular log level](logger-levels).
_subsection: Errors @<errors>
Every error in Ethers has a ``code`` value, which is a string that will
match one of the following error codes.
_heading: Generic Error Codes
_property: Logger.errors.NOT_IMPLEMENTED
The operation is not implemented.
2020-02-18 01:56:13 +03:00
_property: Logger.errors.SERVER_ERROR
There was an error communicating with a server.
2020-02-25 22:57:11 +03:00
_property: Logger.errors.TIMEOUT @<error-timeout>
2020-02-18 01:56:13 +03:00
A timeout occurred.
2020-02-25 22:57:11 +03:00
_property: Logger.errors.UNKNOWN_ERROR @<error-unknown>
A generic unknown error.
_property: Logger.errors.UNSUPPORTED_OPERATION @<error-unsupported>
The operation is not supported.
_heading: Safety Error Codes
2020-02-18 01:56:13 +03:00
_property: Logger.errors.BUFFER_OVERRUN
The amount of data needed is more than the amount of data required,
which would cause the data buffer to read past its end.
2020-02-25 22:57:11 +03:00
_property: Logger.errors.NUMERIC_FAULT @<error-numericfault>
2020-02-18 01:56:13 +03:00
There was an invalid operation done on numeric values.
Common cases of this occur when there is [[link-wiki-overflow]],
[[link-wiki-underflow]] in fixed numeric types or division by zero.
2020-02-25 22:57:11 +03:00
_heading: Usage Error Codes
_property: Logger.errors.INVALID_ARGUMENT @<error-invalidargument>
2020-02-18 01:56:13 +03:00
The type or value of an argument is invalid. This will generally also
include the ``name`` and ``value`` of the argument. Any function which
accepts sensitive data (such as a private key) will include the string
2020-02-25 22:57:11 +03:00
``[\[REDACTED]\]`` instead of the value passed in.
2020-02-18 01:56:13 +03:00
2020-02-25 22:57:11 +03:00
_property: Logger.errors.MISSING_ARGUMENT @<error-missingargument>
2020-02-18 01:56:13 +03:00
An expected parameter was not specified.
2020-02-25 22:57:11 +03:00
_property: Logger.errors.MISSING_NEW @<error-missingnew>
An object is a Class, but is now being called with ``new``.
_property: Logger.errors.UNEXPECTED_ARGUMENT @<error-unexpectedargument>
2020-02-18 01:56:13 +03:00
Too many parameters we passed into a function.
2020-02-25 22:57:11 +03:00
_heading: Ethereum Error Codes
2020-02-18 01:56:13 +03:00
_property: Logger.errors.CALL_EXCEPTION
An attempt to call a blockchain contract (getter) resulted in a
revert or other error.
_property: Logger.errors.INSUFFICIENT_FUNDS
The account is attempting to make a transaction which costs more than is
available.
A sending account must have enough ether to pay for the value, the gas limit
(at the gas price) as well as the intrinsic cost of data. The intrinsic cost
of data is 4 gas for each zero byte and 68 gas for each non-zero byte.
2020-02-25 22:57:11 +03:00
_property: Logger.errors.NETWORK_ERROR
An Ethereum network validation error, such as an invalid chain ID.
2020-02-18 01:56:13 +03:00
_property: Logger.errors.NONCE_EXPIRED
The nonce being specified has already been used in a mined transaction.
_property: Logger.errors.REPLACEMENT_UNDERPRICED
When replacing a transaction, by using a nonce which has already been sent to
the network, but which has not been mined yet the new transaction must specify
a higher gas price.
This error occurs when the gas price is insufficient to //bribe// the transaction
pool to prefer the new transaction over the old one. Generally, the new gas price
should be about 50% + 1 wei more, so if a gas price of 10 gwei was used, the
replacement should be 15.000000001 gwei.
_property: Logger.errors.UNPREDICTABLE_GAS_LIMIT
When estimating the required amount of gas for a transaction, a node is queried for
its best guess.
If a node is unable (or unwilling) to predict the cost, this error occurs.
The best remedy for this situation is to specify a gas limit in the transaction
manually.
This error can also indicate that the transaction is expected to fail regardless,
if for example an account with no tokens is attempting to send a token.
2020-02-25 22:57:11 +03:00
_subsection: Log Levels @<logger-levels>
2020-02-18 01:56:13 +03:00
2020-02-25 22:57:11 +03:00
_property: Logger.levels.DEBUG
Log all output, including debugging information.
_property: Logger.levels.INFO
Only log output for infomational, warnings and errors.
_property: Logger.levels.WARNING
Only log output for warnings and errors.
_property: Logger.levels.ERROR
Only log output for errors.
2020-02-18 01:56:13 +03:00
2020-02-25 22:57:11 +03:00
_property: Logger.levels.OFF
Do not output any logs.