FileDocCategorySizeDatePackage
CLILogger.javaAPI DocGlassfish v2 API7978Fri May 04 22:25:20 BST 2007com.sun.enterprise.cli.framework

CLILogger

public class CLILogger extends Object
author
pa100654

Fields Summary
private static CLILogger
logger
private Logger
s1asLogger
private static final String
DEBUG_FLAG
private static final int
kDefaultBufferSize
private static final String
PACKAGE_NAME
Constructors Summary
protected CLILogger()
Creates a new instance of CLILogger

    
           
      
    
        s1asLogger = Logger.getLogger(PACKAGE_NAME, null);
        if (System.getProperty(DEBUG_FLAG) != null) 
            s1asLogger.setLevel(Level.FINEST);
        else
	{
            s1asLogger.setLevel(Level.INFO);
            //s1asLogger.setLevel(Level.SEVERE);
	}
        s1asLogger.addHandler(new CLILoggerHandler());
        s1asLogger.setUseParentHandlers(false);
    
Methods Summary
public static synchronized com.sun.enterprise.cli.framework.CLILoggergetInstance()
returns the instance of the logger

        if (logger == null)
        {
            logger = new CLILogger();
        }
        return logger;
    
public java.util.logging.LevelgetOutputLevel()
returns the current output Level

return
Level the java.util.logging.Level

        return s1asLogger.getLevel();
    
public static booleanisDebug()

        if (System.getProperty(DEBUG_FLAG) != null) {
            return true;
        } else {
            return false;
        }
    
public static voidmain(java.lang.String[] args)

        CLILogger logger = new CLILogger();
	try 
	{
	    String sLevel = null;
	    // LocalStringsManager lsm = LocalStringsManagerFactory.getLocalStringsManager("com.sun.enterprise.cli.framework", "LocalStrings" );
	    LocalStringsManager lsm = LocalStringsManagerFactory.getFrameworkLocalStringsManager();

	    InputsAndOutputs.getInstance().getUserOutput().print(lsm.getString("PROMPT"));
	    sLevel = InputsAndOutputs.getInstance().getUserInput().getLine();
	    logger.setOutputLevel(java.util.logging.Level.parse(sLevel));

	    System.out.println("Logger level = " + logger.getOutputLevel());
	    logger.printDetailMessage("Fine");
	    logger.printMessage("Info");
	    logger.printError("Error");
	    logger.printWarning("Warning");
	    logger.printDebugMessage("Debug");

	    // test from file
	    InputsAndOutputs.getInstance().setUserOutputFile("UserOutput.txt");
	    InputsAndOutputs.getInstance().setErrorOutputFile("ErrorOutput.txt");
	    InputsAndOutputs.getInstance().setUserInputFile("test_input.txt");
	    InputsAndOutputs.getInstance().getUserOutput().print(lsm.getString("PROMPT"));
	    sLevel = InputsAndOutputs.getInstance().getUserInput().getLine();
	    logger.setOutputLevel(java.util.logging.Level.parse(sLevel));
	    logger.printDetailMessage("Fine");
	    logger.printMessage("Info");
	    logger.printError("Error");
	    logger.printWarning("Warning");
	    logger.printDebugMessage("Debug");

	}
	catch (Exception e)
	{
	    logger.printExceptionStackTrace(e);
	    //e.printStackTrace();
	}
    
public voidprintDebugMessage(java.lang.String message)
prints the message with level as FINEST

param
message the message to be written on the output stream

        s1asLogger.log(Level.FINEST, message);
    
public voidprintDetailMessage(java.lang.String message)
prints the message with level as FINE

param
message the message to be written on the output stream

        s1asLogger.log(Level.FINE, message);
    
public voidprintError(java.lang.String message)
prints the message with level as SEVERE

param
message the message to be written on the output stream

        s1asLogger.log(Level.SEVERE, message);
    
public voidprintExceptionStackTrace(java.lang.Throwable e)
prints the exception message with level as FINEST

param
e - the exception object to print

	/*
	java.lang.StackTraceElement[] ste = e.getStackTrace();
	for (int ii=0; ii<ste.length; ii++)
        {
	    printDebugMessage(ste[ii].toString());
	}
	*/
    	final ByteArrayOutputStream output = new ByteArrayOutputStream( kDefaultBufferSize );
    	e.printStackTrace( new java.io.PrintStream(output));
        printDebugMessage(output.toString());
    
public voidprintMessage(java.lang.String message)
prints the message with level as INFO

param
message the message to be written on the output stream

        s1asLogger.log(Level.INFO, message);
    
public voidprintWarning(java.lang.String message)
prints the message with level as WARNING

param
message the message to be written on the output stream

        s1asLogger.log(Level.WARNING, message);
    
public voidsetOutputLevel(java.util.logging.Level level)
Sets the output Level

param
level the java.util.logging.Level

        if (System.getProperty(DEBUG_FLAG) == null) 
            s1asLogger.setLevel(level);