javauis/lcdui_qt/src/javax/microedition/lcdui/Logger.java
changeset 23 98ccebc37403
parent 21 2a9601315dfc
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: 
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 package javax.microedition.lcdui;
    17 package javax.microedition.lcdui;
    18 
    18 
    19 
    19 
    20 /**
    20 /**
    21  * Logger utility class.<br>
    21  * Logger utility class.<br>
    22  */
    22  */
    23 final class Logger {
    23 final class Logger
       
    24 {
    24 
    25 
    25     private static StringBuffer methodSb = new StringBuffer();
    26     private static StringBuffer methodSb = new StringBuffer();
    26 
    27 
    27     private static boolean logVerbose = true;
    28     private static boolean logVerbose = true;
    28 
    29 
    29     private Logger() {
    30     private Logger()
       
    31     {
    30     }
    32     }
    31 
    33 
    32     /**
    34     /**
    33      * Checks if this logging level will be logged.
    35      * Checks if this logging level will be logged.
    34      *
    36      *
    35      * @param level logging level
    37      * @param level logging level
    36      */
    38      */
    37     static boolean isLogVerbose() {
    39     static boolean isLogVerbose()
       
    40     {
    38         return logVerbose;
    41         return logVerbose;
    39     }
    42     }
    40 
    43 
    41     static void method(Object obj, String fn) {
    44     static void method(Object obj, String fn)
       
    45     {
    42         method(obj, fn, null, null, null);
    46         method(obj, fn, null, null, null);
    43     }
    47     }
    44 
    48 
    45     static void method(Object obj, String fn, Object p1) {
    49     static void method(Object obj, String fn, Object p1)
       
    50     {
    46         method(obj, fn, p1, null, null);
    51         method(obj, fn, p1, null, null);
    47     }
    52     }
    48     static void method(Object obj, String fn, Object p1, Object p2) {
    53     static void method(Object obj, String fn, Object p1, Object p2)
       
    54     {
    49         method(obj, fn, p1, p2, null);
    55         method(obj, fn, p1, p2, null);
    50     }
    56     }
    51 
    57 
    52     /**
    58     /**
    53      * Used for logging a method call.
    59      * Used for logging a method call.
    56      * @param fn the method name
    62      * @param fn the method name
    57      * @param p1 first parameter
    63      * @param p1 first parameter
    58      * @param p2 second parameter
    64      * @param p2 second parameter
    59      * @param p3 third parameter
    65      * @param p3 third parameter
    60      */
    66      */
    61     static void method(Object obj, String fn, Object p1, Object p2, Object p3) {
    67     static void method(Object obj, String fn, Object p1, Object p2, Object p3)
    62         if (logVerbose) {
    68     {
       
    69         if(logVerbose)
       
    70         {
    63             methodSb.setLength(0);
    71             methodSb.setLength(0);
    64             methodSb.append(obj);
    72             methodSb.append(obj);
    65             methodSb.append("::");
    73             methodSb.append("::");
    66             methodSb.append(fn);
    74             methodSb.append(fn);
    67             methodSb.append("(");
    75             methodSb.append("(");
    68             if (p1 != null) {
    76             if(p1 != null)
       
    77             {
    69                 methodSb.append(p1);
    78                 methodSb.append(p1);
    70             }
    79             }
    71             if (p2 != null) {
    80             if(p2 != null)
       
    81             {
    72                 methodSb.append(", ");
    82                 methodSb.append(", ");
    73                 methodSb.append(p2);
    83                 methodSb.append(p2);
    74             }
    84             }
    75             if (p3 != null) {
    85             if(p3 != null)
       
    86             {
    76                 methodSb.append(", ");
    87                 methodSb.append(", ");
    77                 methodSb.append(p3);
    88                 methodSb.append(p3);
    78             }
    89             }
    79             methodSb.append(")");
    90             methodSb.append(")");
    80             com.nokia.mj.impl.utils.Logger.LOG(
    91             com.nokia.mj.impl.utils.Logger.LOG(
    81                     com.nokia.mj.impl.utils.Logger.EJavaUI,
    92                 com.nokia.mj.impl.utils.Logger.EJavaUI,
    82                     com.nokia.mj.impl.utils.Logger.EInfo, methodSb.toString());
    93                 com.nokia.mj.impl.utils.Logger.EInfo, methodSb.toString());
    83         }
    94         }
    84     }
    95     }
    85 
    96 
    86     /**
    97     /**
    87      * Log VERBOSE level message.
    98      * Log VERBOSE level message.
    88      *
    99      *
    89      * @param msg a message
   100      * @param msg a message
    90      */
   101      */
    91     static void verbose(String msg) {
   102     static void verbose(String msg)
       
   103     {
    92         com.nokia.mj.impl.utils.Logger.LOG(
   104         com.nokia.mj.impl.utils.Logger.LOG(
    93                 com.nokia.mj.impl.utils.Logger.EJavaUI,
   105             com.nokia.mj.impl.utils.Logger.EJavaUI,
    94                 com.nokia.mj.impl.utils.Logger.EInfo, msg);
   106             com.nokia.mj.impl.utils.Logger.EInfo, msg);
    95     }
   107     }
    96 
   108 
    97     /**
   109     /**
    98      * Log INFO level message.
   110      * Log INFO level message.
    99      *
   111      *
   100      * @param msg a message
   112      * @param msg a message
   101      */
   113      */
   102     static void info(String msg) {
   114     static void info(String msg)
       
   115     {
   103         com.nokia.mj.impl.utils.Logger.LOG(
   116         com.nokia.mj.impl.utils.Logger.LOG(
   104                 com.nokia.mj.impl.utils.Logger.EJavaUI,
   117             com.nokia.mj.impl.utils.Logger.EJavaUI,
   105                 com.nokia.mj.impl.utils.Logger.EInfo, msg);
   118             com.nokia.mj.impl.utils.Logger.EInfo, msg);
   106     }
   119     }
   107 
   120 
   108     /**
   121     /**
   109      * Log WARNING level message.
   122      * Log WARNING level message.
   110      *
   123      *
   111      * @param msg a message
   124      * @param msg a message
   112      */
   125      */
   113     static void warning(String msg) {
   126     static void warning(String msg)
       
   127     {
   114         com.nokia.mj.impl.utils.Logger.WLOG(
   128         com.nokia.mj.impl.utils.Logger.WLOG(
   115                 com.nokia.mj.impl.utils.Logger.EJavaUI, msg);
   129             com.nokia.mj.impl.utils.Logger.EJavaUI, msg);
   116     }
   130     }
   117 
   131 
   118     /**
   132     /**
   119      * Log an EXCEPTION (ERROR level).
   133      * Log an EXCEPTION (ERROR level).
   120      *
   134      *
   121      * @param msg a message
   135      * @param msg a message
   122      */
   136      */
   123     static void exception(String msg, Exception e) {
   137     static void exception(String msg, Exception e)
       
   138     {
   124         com.nokia.mj.impl.utils.Logger.ELOG(
   139         com.nokia.mj.impl.utils.Logger.ELOG(
   125                 com.nokia.mj.impl.utils.Logger.EJavaUI, msg, e);
   140             com.nokia.mj.impl.utils.Logger.EJavaUI, msg, e);
   126         // e.printStackTrace();
   141         // e.printStackTrace();
   127     }
   142     }
   128 
   143 
   129     /**
   144     /**
   130      * Log ERROR level message.
   145      * Log ERROR level message.
   131      *
   146      *
   132      * @param msg a message
   147      * @param msg a message
   133      */
   148      */
   134     static void error(String msg) {
   149     static void error(String msg)
       
   150     {
   135         com.nokia.mj.impl.utils.Logger.ELOG(
   151         com.nokia.mj.impl.utils.Logger.ELOG(
   136                 com.nokia.mj.impl.utils.Logger.EJavaUI, msg);
   152             com.nokia.mj.impl.utils.Logger.EJavaUI, msg);
   137     }
   153     }
   138 
   154 
   139     /**
   155     /**
   140      * Indents a string with the given number of spaces.
   156      * Indents a string with the given number of spaces.
   141      */
   157      */
   142     static String indent(String str, int numSpacesBefore) {
   158     static String indent(String str, int numSpacesBefore)
       
   159     {
   143         String ret = (str == null ? "" : str);
   160         String ret = (str == null ? "" : str);
   144         for (int i = 0; i < numSpacesBefore; i++) {
   161         for(int i = 0; i < numSpacesBefore; i++)
       
   162         {
   145             ret = " " + ret;
   163             ret = " " + ret;
   146         }
   164         }
   147         return ret;
   165         return ret;
   148     }
   166     }
   149 
   167