Home / GitHub Page

About logging and debugging CliClient

Hello, dear community.

I didn’t quite get how the logging works. I wanted to debug joplin/ElectronClient/lib/reducer.js so I imported the logger module and tried to print the debug message as below:

const { Logger } = require('lib/logger');
const logger = new Logger();

... some code inside reducer.js ...

const { Logger } = require('lib/logger');
const logger = new Logger();
const reducer = (state = defaultState, action) => {
...
  		case 'SEARCH_ADD':
			{
				newState = Object.assign({}, state);
				const searches = newState.searches.slice();
				searches.push(action.search);
                                logger.debug(searches);
                                // i've also tried logger.info(searches);
				newState.searches = searches;
			}
			break;


...
}

And then I run npm start in the root project directory. But then the changes I made to the code disappeared. I also tried just changing the reducer.js inside the CliClient/build/lib
and then instead of npm start I run node 'main.js' --profile ~/Temp/TestNotes2 --stack-trace-enabled --log-level debug --env dev. In this case, the changes I made to the reducer.js persisted, but even then I didn’t see any debug output I tried to make in ~/Temp/TestNotes2/log.txt. Could you give me the advice how to use Logger? Also want to know your development workflow in general, like how you debug and test.

Best regards,

Azamat Rsymbetov

Not sure if it’s the best way but what works for me is importing registry.js and using logger from there:

const { reg } = require('lib/registry.js');
...

reg.logger().info('...');
1 Like

Thanks! That solved my problem

The way it works is that the lib/ folder is copied from ReactNativeClient to the other two client folders every time you start the Electron app. So any changes made in ElectronClient/lib would be overwritten by the ReactNativeClient/lib directory. If you want to test changes on lib/, you would need to change it in ReactNativeClient/lib (in this case, ReactNativeClient/lib/reducer.js)

1 Like