Logger
The Logger
utility provides basic functionalities to help debug and monitor operations within the DID Spaces SDK. This utility is part of the broader Utilities section, which offers various helper functions for common tasks.
Basic Logging with logger
#
The SDK exposes a logger
object, which is currently an alias for the standard JavaScript console
object. This allows you to use familiar console
methods for outputting information, warnings, and errors to your development console for debugging and monitoring purposes.
While future enhancements might integrate more advanced logging capabilities (such as @blocklet/logger
), the current implementation offers direct access to console
's functionalities.
Example
import { logger } from '@arcblock/did-spaces-client';
logger.log('This is a log message.');
logger.info('This is an informational message.');
logger.warn('This is a warning message!');
logger.error('This is an error message.', new Error('Something went wrong.'));
This example demonstrates how to use the logger
object, mirroring the behavior of console
, to output different types of messages.
Timestamping with now
#
The now
utility function provides a formatted timestamp, which can be useful when prepending timestamps to your log messages for better traceability and debugging.
Parameters
This function takes no parameters.
Returns
Name | Type | Description |
---|---|---|
|
| A string representing the current date and time in |
Example
import { logger, now } from '@arcblock/did-spaces-client';
logger.log(`[${now()}] Application started.`);
logger.warn(`[${now()}] Data inconsistency detected.`);
This example shows how to integrate the now
function with your logger
calls to include precise timestamps, making it easier to track events chronologically in your application logs.
This section covered the basic logging and timestamping utilities available in the DID Spaces SDK. For more detailed information on other helper functions, explore the DID utilities.