# Debugging

Cornerstone Tools is using the debug (opens new window) library for logging debug information.

By default, in the minified "production" build of cornerstone tools, only errors will be logged to the console.

When using the un-minified or "development" build, you may also see some warnings logged to the console in some scenarios.

But there is more log information available if you need it.

# Turing debug logs on and off

cornerstoneTools exports enableLogger and disableLogger methods as top level api methods.

enableLogger takes a scoping string with which you can specify scopes to be included / excluded.

Multiple scopes are comma separated. Excluding a scope is done by prefixing with -. You can use the * match against many scopes.

import csTools from 'cornerstone-tools';

// Enable logging
csTools.enableLogger();
// defaults to "cornerstoneTools:*" which will print all logs from the cornerstoneTools package

// This is just some sugar ontop of the debug library. You can enable all
// debug logging – including things outside of cornerstoneTools
csTools.enableLogger('*');

// Only show logs from setToolMode.js
csTools.enableLogger('cornerstoneTools:store:setToolMode');

// Show all logs, but exclude the eventDispatchers (which can be a bit noisy)
csTools.enableLogger('cornerstoneTools:*,-cornerstoneTools:eventDispatchers:*');

// Disable logging
const prevSettings = csTools.disableLogger();
// `disableLogger` returns a string of the previous settings in case
// you wanted to toggle logging off and back on later.

// Eg. this would re-enable the previous settings
csTools.enableLogging(prevSettings);

As this is based on the wonderful debug library, you can also enable/disable the logger when you don't have access to csTools by using localStorage.

// This will enable all cornerstoneTools logs
localStorage.setItem('debug', 'cornerstoneTools:*');
// You will need to refresh the browser for this setting to take effect