javacommons/utils/javasrc/com/nokia/mj/impl/utils/Logger.java
changeset 79 2f468c1958d0
parent 76 4ad59aaee882
child 80 d6dafc5d983f
equal deleted inserted replaced
76:4ad59aaee882 79:2f468c1958d0
   170         }
   170         }
   171 
   171 
   172         catch (Exception e)
   172         catch (Exception e)
   173         {
   173         {
   174 
   174 
   175             System.out.println(e.toString());
   175             System.err.println(e.toString());
   176         }
   176         }
   177     }
   177     }
   178 
   178 
   179     /**
   179     /**
   180      * Logging function for error messages
   180      * Logging function for error messages
   181      * @param component a unique id of component
   181      * @param component a unique id of component
   182      * @param str emiting information
   182      * @param str emiting information
   183      */
   183      */
   184     public static void ELOG(int component, String str)
   184     public static void ELOG(int component, String str)
   185     {
   185     {
   186         _logging(component, EError, str);
   186         logImpl(component, EError, str);
   187     }
   187     }
   188 
   188 
   189     /**
   189     /**
   190      * Logging function for errors, prints exception info and a backtrace of the stack
   190      * Logging function for errors, prints exception info and a backtrace of the stack
   191      * @param component a unique id of component
   191      * @param component a unique id of component
   192      * @param str emiting information
   192      * @param str emiting information
   193      * @param thrown exception object
   193      * @param thrown exception object
   194      */
   194      */
   195     public static void ELOG(int component, String str, Throwable thrown)
   195     public static void ELOG(int component, String str, Throwable thrown)
   196     {
   196     {
   197 
   197         logImpl(component, EError, str, thrown);
   198         ByteArrayOutputStream byte_stream = new ByteArrayOutputStream();
       
   199         PrintStream print_stream = new PrintStream(byte_stream);
       
   200 
       
   201         _loggingException(component, EError, str, thrown, byte_stream, print_stream);
       
   202 
       
   203     }
   198     }
   204 
   199 
   205     /**
   200     /**
   206      * Logging function for warning messages
   201      * Logging function for warning messages
   207      * @param component a unique id of component
   202      * @param component a unique id of component
   208      * @param str emiting information
   203      * @param str emiting information
   209      */
   204      */
   210     public static void WLOG(int component, String str)
   205     public static void WLOG(int component, String str)
   211     {
   206     {
   212         _logging(component, EWarning, str);
   207         logImpl(component, EWarning, str);
   213     }
   208     }
   214 
   209 
   215     /**
   210     /**
   216      * Logging function for warnings, prints exception info and a backtrace of the stack
   211      * Logging function for warnings, prints exception info and a backtrace of the stack
   217      * @param component a unique id of component
   212      * @param component a unique id of component
   218      * @param str emiting information
   213      * @param str emiting information
   219      * @param thrown exception object
   214      * @param thrown exception object
   220      */
   215      */
   221     public static void WLOG(int component, String str, Throwable thrown)
   216     public static void WLOG(int component, String str, Throwable thrown)
   222     {
   217     {
   223         ByteArrayOutputStream byte_stream = new ByteArrayOutputStream();
   218         logImpl(component, EWarning, str, thrown);
   224         PrintStream print_stream = new PrintStream(byte_stream);
       
   225 
       
   226         _loggingException(component, EWarning, str, thrown, byte_stream, print_stream);
       
   227     }
   219     }
   228 
   220 
   229     /**
   221     /**
   230      * Logging function for information ending to the products
   222      * Logging function for information ending to the products
   231      * @param component a unique id of component
   223      * @param component a unique id of component
   232      * @param str emiting information
   224      * @param str emiting information
   233      */
   225      */
   234     public static void PLOG(int component, String str)
   226     public static void PLOG(int component, String str)
   235     {
   227     {
   236         _logging(component, EInfoPrd, str);
   228         logImpl(component, EInfoPrd, str);
   237     }
   229     }
   238 
   230 
   239     /**
   231     /**
   240      * Logging function for information ending to the products,
   232      * Logging function for information ending to the products,
   241      * prints exception info and a backtrace of the stack
   233      * prints exception info and a backtrace of the stack
   243      * @param str emiting information
   235      * @param str emiting information
   244      * @param thrown exception object
   236      * @param thrown exception object
   245      */
   237      */
   246     public static void PLOG(int component, String str, Throwable thrown)
   238     public static void PLOG(int component, String str, Throwable thrown)
   247     {
   239     {
   248         ByteArrayOutputStream byte_stream = new ByteArrayOutputStream();
   240         logImpl(component, EInfoPrd, str, thrown);
   249         PrintStream print_stream = new PrintStream(byte_stream);
       
   250         _loggingException(component, EInfoPrd, str, thrown, byte_stream, print_stream);
       
   251     }
   241     }
   252 
   242 
   253     /**
   243     /**
   254      * Logging function for information ending to the debug releases
   244      * Logging function for information ending to the debug releases
   255      * @param component a unique id of component
   245      * @param component a unique id of component
   256      * @param str emiting information
   246      * @param str emiting information
   257      */
   247      */
   258     public static void ILOG(int component, String str)
   248     public static void ILOG(int component, String str)
   259     {
   249     {
   260         _logging(component, EInfo, str);
   250         logImpl(component, EInfo, str);
   261     }
   251     }
   262 
   252 
   263     /**
   253     /**
   264      * Logging function for information ending to the debug releases,
   254      * Logging function for information ending to the debug releases,
   265      * prints exception info and a backtrace of the stack
   255      * prints exception info and a backtrace of the stack
   267      * @param str emiting information
   257      * @param str emiting information
   268      * @param thrown exception object
   258      * @param thrown exception object
   269      */
   259      */
   270     public static void ILOG(int component, String str, Throwable thrown)
   260     public static void ILOG(int component, String str, Throwable thrown)
   271     {
   261     {
   272         ByteArrayOutputStream byte_stream = new ByteArrayOutputStream();
   262         logImpl(component, EInfo, str, thrown);
   273         PrintStream print_stream = new PrintStream(byte_stream);
       
   274         _loggingException(component, EInfoPrd, str, thrown, byte_stream, print_stream);
       
   275     }
   263     }
   276 
   264 
   277     /**
   265     /**
   278      * Used for function entries,
   266      * Used for function entries,
   279      * e.g. JELOG(Logger.EJavaCaptain, "-> myFunction()"
   267      * e.g. JELOG(Logger.EJavaCaptain, "-> myFunction()"
   282      */
   270      */
   283     public static void JELOG(int component, String str)
   271     public static void JELOG(int component, String str)
   284     {
   272     {
   285         if (Activated[component])
   273         if (Activated[component])
   286         {
   274         {
   287             _logging(component, EEntry, str);
   275             logImpl(component, EEntry, str);
   288         }
   276         }
   289     }
   277     }
   290 
   278 
   291     /**
   279     /**
   292      * Used for high load data
   280      * Used for high load data
   295      */
   283      */
   296     public static void HLOG(int component, String str)
   284     public static void HLOG(int component, String str)
   297     {
   285     {
   298         if (Activated[component])
   286         if (Activated[component])
   299         {
   287         {
   300             _logging(component, EInfoHeavyLoad, str);
   288             logImpl(component, EInfoHeavyLoad, str);
   301         }
   289         }
   302     }
   290     }
   303 
   291 
   304     /**
   292     /**
   305      * Function for emitting debug traces at development time.
   293      * Function for emitting debug traces at development time.
   309      * @param str emiting information
   297      * @param str emiting information
   310      */
   298      */
   311     public static void LOG(int component, int level, String str)
   299     public static void LOG(int component, int level, String str)
   312     {
   300     {
   313         if (Activated[component])
   301         if (Activated[component])
   314             _logging(component, level, str);
   302         {
       
   303             logImpl(component, level, str);
       
   304         }
   315     }
   305     }
   316 
   306 
   317     /**
   307     /**
   318      * Function for printing an exception info and a backtrace of the stack to log at development time
   308      * Function for printing an exception info and a backtrace of the stack to log at development time
   319      * This does not do anything in release builds
   309      * This does not do anything in release builds
   324      */
   314      */
   325     public static void LOG(int component, int level, String str, Throwable thrown)
   315     public static void LOG(int component, int level, String str, Throwable thrown)
   326     {
   316     {
   327         if (Activated[component])
   317         if (Activated[component])
   328         {
   318         {
   329             ByteArrayOutputStream byte_stream = new ByteArrayOutputStream();
   319             logImpl(component, level, str, thrown);
   330             PrintStream print_stream = new PrintStream(byte_stream);
   320         }
   331 
   321     }
   332             _loggingException(component, level, str, thrown, byte_stream, print_stream);
   322     /**
   333         }
   323      * Function for printing a log without an exception.
   334     }
   324      * @param component a unique id of component
   335 
   325      * @param level id level of tracing information
   336 
   326      * @param str emiting information
   337     /** Native function prototype. */
   327      */
   338     private static native void _logging(int component, int level, String str);
   328     private static void logImpl(int component, int level, String str)
   339 
   329     {
   340     /** Native function for logging stack trace when exception happend */
   330         logImpl(component, level, str, null);
   341     private static native void _loggingException(int component, int level, String str, Throwable thrown,
   331     }
   342             ByteArrayOutputStream byte_stream, PrintStream print_stream);
   332 
   343 
   333     /**
       
   334      * Function for printing a log with optional exception.
       
   335      * @param component a unique id of component
       
   336      * @param level id level of tracing information
       
   337      * @param str emiting information
       
   338      * @param thrown exception object. If null then ignored
       
   339      */
       
   340     private static void logImpl(int component, int level, String str, Throwable thrown)
       
   341     {
       
   342         if (str == null)
       
   343         {
       
   344             ELOG(component, "str argument was null!", new NullPointerException());
       
   345         }
       
   346         else
       
   347         {
       
   348             _logging(component, level, str, DebugUtils.getStackTrace(thrown));
       
   349         }
       
   350     }
       
   351 
       
   352     /**
       
   353      * Native function for printing a log with optional stack trace.
       
   354      * @param component a unique id of component
       
   355      * @param level id level of tracing information
       
   356      * @param str emiting information. Must not be null.
       
   357      * @param stackTrace of the exception object. Can be null and will then
       
   358      *                   be ignored.
       
   359      */
       
   360     private static native void _logging(int component, int level, String str,
       
   361                                         String stackTrace);
   344 }
   362 }