Topic
  • 4 replies
  • Latest Post - ‏2011-11-22T00:36:30Z by Sei*
Sei*
Sei*
5 Posts

Pinned topic Logging in CLI-extended program

‏2011-11-18T08:03:32Z |
Hi, I have a Java batch program that is kicked by a custom CLI command.

The problem is that no logs are output in either trace.log or error.log in the /logs directory.
The code looks like this:
Groovy
def onCliTask() {
    // calls the Java program
    foo();
}
 
Java
public int foo() {
    logger.log(Level.INFO, "foo called");
}

Does anyone know how to enable logging for command-based programs like this?

Thank you
Updated on 2014-03-25T05:43:32Z at 2014-03-25T05:43:32Z by iron-man
  • SystemAdmin
    SystemAdmin
    9224 Posts

    Re: Logging in CLI-extended program

    ‏2011-11-18T20:00:50Z  
    I'm not able to find a sample that demonstrates that, so I'm not sure that user CLI tasks will direct log output to the default sMash logs. Assuming that you are seeing your log output showing up in stderr (meaning that your logging is working), try using the -l command line argument to capture the log messages to a logfile:

    zero -l=myCliTask.log myCliTask
    


    The output does result in a well formatted logfile, complete with timestamps.
    Updated on 2014-03-25T05:44:25Z at 2014-03-25T05:44:25Z by iron-man
  • Sei*
    Sei*
    5 Posts

    Re: Logging in CLI-extended program

    ‏2011-11-21T10:51:43Z  
    Thanks, it worked.

    I needed to change the zero.core.logging.ConsoleHandler settings in logging.properties (which can be found under the sMash install directory) to enable detailed logging.

    Is it correct that this is the property that controls logging in the CLI mode?

    Thank you.
  • SystemAdmin
    SystemAdmin
    9224 Posts

    Re: Logging in CLI-extended program

    ‏2011-11-21T15:11:43Z  
    • Sei*
    • ‏2011-11-21T10:51:43Z
    Thanks, it worked.

    I needed to change the zero.core.logging.ConsoleHandler settings in logging.properties (which can be found under the sMash install directory) to enable detailed logging.

    Is it correct that this is the property that controls logging in the CLI mode?

    Thank you.
    I believe logging.properties sets the default logging characteristics for everything (command line and non-command line). It could affect which level of log messages get captured, but INFO is the default so i don't know why you would have to edit that file, or what edit you would make for the example you posted.
  • Sei*
    Sei*
    5 Posts

    Re: Logging in CLI-extended program

    ‏2011-11-22T00:36:30Z  
    I believe logging.properties sets the default logging characteristics for everything (command line and non-command line). It could affect which level of log messages get captured, but INFO is the default so i don't know why you would have to edit that file, or what edit you would make for the example you posted.
    I wanted to have full stack traces output in the log, which by default is not enabled for ConsoleLogger, and debug logs as well.

    Thank you for your help.