Snap Logs by code

Dear SNAP support, I would like to ask your help for the snap log. As you may know, we integrate SNAP jars in our code to execute workflows and other things.
We need to access the logs, so, with version 6 and 7, we had this snippet of code:

SimpleFormatter oSimpleFormatter = new SimpleFormatter();

FileHandler oFileHandler = new FileHandler(sSnapLogFile, true);

oFileHandler.setLevel(oLogLevel);
oFileHandler.setFormatter(oSimpleFormatter);

SystemUtils.LOG.setLevel(oLogLevel);
SystemUtils.LOG.addHandler(oFileHandler);

This worked very well!
Now we updated to version 8 and we cannot see any log in the file referenced to sSnapLogFile.
Do you have any idea why?
Did anything change maybe? This can be our fault obviously, but since we did not change this part any suggestion will be appreciated.
Thanks
Paolo

1 Like

Hi,

This should still work. I can’t see any changes in this area which might break your code.
Sorry, I have no clue right now.

Hi Marco!! Thanks as always. I’m with you, but this is not logging and I don’t understand.
Just last question: can you double check if it is correct how we set the “General” log level?
This line:
SystemUtils.LOG.setLevel(oLogLevel);
Should apply to all the logs in the SNAP code, can you confirm?
Thank you anyway.
Best Regards,
Paolo

You could try replacing SystemUtils.LOG by Config.instance().logger()

EngneConfig config = Engine.getInstance().getConfig();
config.logLevel(“FINER”); // for example
Logger logger = config.getLogger()
logger.addHandler(oFileHandler)

The log level can also be set by a system property:
It’s name is ‘snap.log.level’.
See also:

Sorry for Late Marco, I had some days of vacation. We will try and let you know.
Thanks a lot

It works!!! Thank you Marco!!!