Clad User Manual - Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 66: Line 66:
==Debug Logging==
==Debug Logging==


Use SLF4J API <tt>debug()</tt> method:


Use SLFJ4 API:
<pre>
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
...


private static final Logger log = LoggerFactory.getLogger(MyClass.class);


==Console Output==
...


<font color=red>
log.debug("...");
TODO
</pre>
</font>


These log messages will be automatically sent to stdout when the [[#-v.7C--verbose|-v|--verbose]] option is used.


==Debug Logging==
==Console Output==


<font color=red>
<font color=red>
TODO
TODO
</font>
</font>
Use SLFJ4 API:
<pre>
</pre>
Also see [[Clad_User_Manual_-_Concepts#-v.7C--verbose|-v|--verbose]] options.


=Error Handling=
=Error Handling=

Revision as of 23:13, 8 November 2016

Internal

Command

A command accepts command options and arguments.

Default Command

An application may not have a default command. In this case, the ApplicationRuntime implementation of public String getDefaultCommand() must return null.

Universal Commands

Command Arguments

The command arguments are a list of space separated free-format strings, that are not options, and that have a special significance for the command.

The command is given a chance to recognize arguments that make sense to it, and "consume" them. The command implementation has a chance to do that when implementing the configure(...) method of the Command interface, or when overriding the corresponding method of the CommandBase abstract class.

The CommandBase configure(...) implementation parses the declared options for the command, so the command only accepts options, it is sufficient to use the default implementation. However, for a more nuanced handling of the command line argument, use:

@Override
public void configure(int from, List<String> commandLineArguments) throws Exception {

    super.configure(from, commandLineArguments);

    //
    // perform additional handling here and remove the arguments that make sense to us
    // from the given list
    //
}

Options

The options (global or specific to a certain command) use the GNU command line option syntax:

 -o <value> | --option=<value>

Global Options

The global options apply to the application runtime, and they are not specific to a certain command.

Universal Global Options

All clad-based application automatically support the following global options. There is no need to declared them among the "required" or "optional" global options for a specific application.

-v|--verbose

-v or --verbose turn on DEBUG on the underlying CONSOLE appender, so the application will display internal execution information at stdout. In order to be displayed in this mode, the internal execution information must be logged by the application with SLFJ4 debug() method. For more details on how to program debug logging, see How to Implement a Command Line Application - Debug Logging.

-d|--debug

-d or --debug, in addition to logging debug information at the CONSOLE the way -v|--verbose options do, start the underlying JVM in debug mode, so a debugger can be attached to it.

Command Options

Logging

The clad framework comes pre-bundled with SLF4J API support, so the command line applications build with clad can use SLF4J for logging. However, clad does not favor any binding, so the application should provide its own SLF4J binding library and the backend logging framework. For details on how do do that, see How to Implement a Command Line Application - SLF4J Integration.

Debug Logging

Use SLF4J API debug() method:

Use SLFJ4 API:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

...

private static final Logger log = LoggerFactory.getLogger(MyClass.class);

...

log.debug("...");

These log messages will be automatically sent to stdout when the -v|--verbose option is used.

Console Output

TODO

Error Handling

If a processing error is caused by what the user did, or by the input data, and it can be corrected by user input (or by data correction), throw an UserErrorException with a human-readable message. The upmost runtime layer must be designed so it displays the error message at stderr and System.exit()s.

Configuration File

Each command line option has a configuration file correspondent. Command line value takes precedence over the configuration file value.