relative / synchrony

javascript-obfuscator cleaner & deobfuscator
https://deobfuscate.relative.im/
GNU General Public License v3.0
892 stars 118 forks source link

[request] API control over output #26

Open gwittel opened 2 years ago

gwittel commented 2 years ago

Currently output is hard coded to console.log which makes this library hard to integrate with other tools. I'd really like an option to pass in a custom logger or console object (using Nodes' Console class) as part of the options object.

It seems simple enough but I see two places that are troublesome:

1) The walk function which outputs to console on error. I don't see a low-disruption way to handle this other than either throwing/catching the exception or passing in a console/logger. 2) The log method in controlflow - similar, but given its a manual debug log probably low priority to change.

I'm happy to help with a PR, but wanted to check interest and direction before proceeding.

relative commented 2 years ago

I can look into implementing this. I attempted to mainly log everything using context.log so it would be easy to change this later and there hopefully should not be many lingering global console references.

I am thinking I can implement a logger field in DeobfuscateOptions which takes an object of type

{
  log(type: 'log' | 'info' | 'warn' | 'error', msg: string): any
  info?(msg: string): any
  warn?(msg: string): any
  error?(msg: string): any
} | boolean

When it is true it will use the global console for logging, when false it will disable logs and when passing an object it will fall through to the log function for any of the methods that aren't defined.

gwittel commented 2 years ago

Sounds great! Thanks!

gBasil commented 11 months ago

There was a pull request regarding a logger option, but it didn't receive any activity and the original author closed it. Any chance it could be revisited?