FileDocCategorySizeDatePackage
Logging.javaAPI DocphoneME MR2 API (J2ME)6164Wed May 02 18:00:10 BST 2007com.sun.midp.log

Logging

public class Logging extends LoggingBase
The purpose of the logging service is to provide a standard means to report runtime information from within Java or native code. The porting process is eased by having to modify one logging service implementation in place of handling the ad hoc use of println(), printf(), putc(), and other functions currently used. An assert mechanism for Java code, implemented using the logging service is also provided here for convenience. This class consists of the Java interface to the functionality of the logging service.

Fields Summary
public static int
REPORT_LEVEL
Flag allowing client code with reporting levels less than this to be compiled out of the build. Callers should use this flag as a way to remove bytecodes related to unneeded levels of reporting from the resulting classfiles. For Example:

if (Logging.REPORT_LEVEL <= severity) {
Logging.report(Logging.<severity>,
LogChannels.<channel>,
"[meaningful message]");
}
public static boolean
ASSERT_ENABLED
Flag allowing client code with assert statements to be compiled out of a production build. Clients of the assertion service should wrap calls to the assert() method to enable them to be removed from builds when desired

if (Logging.ASSERT_ENABLED) {
Logging.assertTrue([eval to boolean], "message");
}
public static boolean
TRACE_ENABLED
Flag to indicate whether tracing is enabled in the Logging service. If the flag is false, calls to the trace() method will have no effect. Callers should use this flag as a type of compile option to remove unnecessary bytecodes from resulting classfiles. For example:
} catch (Throwable t) {
if (Logging.TRACE_ENABLED) {
Logging.trace(t, "[meaningful message]");
}
}
Constructors Summary
Methods Summary
public static voidenableAsserts(int enabled)
Enables or disables assertions.

param
enabled > 0 - enable assertions, == 0 - disable it, < 0 - don't change the current setting

        if (enabled >= 0) {
            ASSERT_ENABLED = (enabled > 0);
        }
    
public static voidenableTrace(int enabled)
Enables or disables tracing.

param
enabled > 0 - enable tracing, == 0 - disable it, < 0 - don't change the current setting

        if (enabled >= 0) {
            TRACE_ENABLED = (enabled > 0);
        }
    
public static voidinitLogSettings(int suiteId)
Loads the logging settings for the specified suite.

param
suiteId ID of the suite for which the settings must be loaded

        /*
         * IMPL_NOTE: parseMidpControlArg0() saves the parsed data into a global
         * variables in native, it's not MVM-safe. But initLogSettings()
         * is called during starting of a new midlet, and the situation when
         * several midlets are started simultaneously is hardly ever possible.
         */
        if (parseMidpControlArg0(suiteId)) {
            setReportLevel(loadReportLevel0());
            enableTrace(loadTraceEnabled0());
            enableAsserts(loadAssertEnabled0());
        }
    
private static native intloadAssertEnabled0()
Loads a value defining if assertions are enabled.

return
> 0 - enable assertions, == 0 - disable it, < 0 - don't change the current setting

private static native intloadReportLevel0()
Loads a report level.

return
report level that was loaded

private static native intloadTraceEnabled0()
Loads a value defining if tracing is enabled.

return
> 0 - enable tracing, == 0 - disable it, < 0 - don't change the current setting

private static native booleanparseMidpControlArg0(int suiteId)
Parses the value of MIDP_ARGS attribute set in the JAD file of the given midlet suite.

param
suiteId ID of the suite whose the settings must be parsed
return
true if one or more logging setting must be changed, false otherwise

public static voidsetReportLevel(int newReportLevel)
Sets a new report level.

param
newReportLevel new report level


                   
         
        if (newReportLevel != Constants.LOG_CURRENT) {
            REPORT_LEVEL = newReportLevel;
        }