log utility is a function that's used for logging debugging, warning, and error information about the application. Use this utility by importing
@shopify/hydrogen, or by using a
log prop passed to each page component. We recommend using the
log prop passed to each page because it will associate your log to the current request in progress.
Example codeAnchor link to section titled "Example code"
Return typeAnchor link to section titled "Return type"
Return an object with methods for logging information at different priorities:
||The lowest priority logs. These logs are very verbose.|
||The normal priority logs. Used internally for logging route timing information.|
||The high priority warnings that might or might not cause the application to fail.|
||The logging used for errors or invalid application state.|
||The logging used just prior to the process exiting.|
Logger optionsAnchor link to section titled "Logger options"
Logger has the following Boolean options:
||Logs the cache status of each stored entry:
||Logs the cache control headers of the main document and its sub queries.|
||Logs the timeline of when queries are being requested, resolved, and rendered.|
||Logs warnings in your app if you're over-fetching data from the Storefront API.|
Swap logger implementationAnchor link to section titled "Swap logger implementation"
Hydrogen includes a default logger implementation that can be swapped for a logger of your choice. You can call
setLogger with your own implementation. The first argument of each log method will contain a
request object if the log was called in the same context as a request: