Skip to content

Commit

Permalink
Merge pull request #904 from mikehazell/pr/logging
Browse files Browse the repository at this point in the history
Replace console.log calls with debug
  • Loading branch information
dannyrb authored Apr 4, 2019
2 parents 0aff928 + 624b405 commit 8e63394
Show file tree
Hide file tree
Showing 38 changed files with 581 additions and 217 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = {
//'init-declarations': 'warn',
'import/default': 'warn',
'import/export': 'warn',
'import/extensions': ['warn', { js: 'always' }],
'import/extensions': ['warn', { js: 'ignorePackages' }],
'import/first': 'warn',
'import/named': 'warn',
'import/namespace': 'warn',
Expand Down Expand Up @@ -99,7 +99,7 @@ module.exports = {
'no-caller': 'warn',
'no-catch-shadow': 'warn',
'no-confusing-arrow': 'warn',
'no-console': 'off',
'no-console': 'error',
'no-div-regex': 'warn',
'no-duplicate-imports': 'warn',
'no-else-return': 'warn',
Expand Down
11 changes: 7 additions & 4 deletions config/webpack/webpack-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ const baseConfig = require('./webpack-base');
const devConfig = {
devServer: {
hot: true,
publicPath: '/dist/'
publicPath: '/dist/',
},
plugins: [
new webpack.HotModuleReplacementPlugin({})
]
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
new webpack.HotModuleReplacementPlugin({}),
],
};

module.exports = merge(baseConfig, devConfig);
module.exports = merge(baseConfig, devConfig);
18 changes: 12 additions & 6 deletions config/webpack/webpack-prod.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
const webpack = require('webpack');
const merge = require('./merge');
const baseConfig = require('./webpack-base');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

const prodConfig = {
output: {
filename: '[name].min.js'
filename: '[name].min.js',
},
mode: "production",
mode: 'production',
optimization: {
minimizer: [
new UglifyJSPlugin({
sourceMap: true
})
]
sourceMap: true,
}),
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
],
};

module.exports = merge(baseConfig, prodConfig);
module.exports = merge(baseConfig, prodConfig);
1 change: 1 addition & 0 deletions docs/latest/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

## Misc

- [Debugging](debugging/index.md)
- [API](https://tools.cornerstonejs.org/api/)
- 3rd Party Tool Directory _coming soon_
- Custom Tool Example Repositories _coming soon_
54 changes: 54 additions & 0 deletions docs/latest/debugging/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Debugging

Cornerstone Tools is using the [`debug`](https://github.com/visionmedia/debug/) 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.

```js
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`.

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

0 comments on commit 8e63394

Please sign in to comment.