Blogia
JavaForDummies

Trucos

Patrones para usar el LOG 4 j

Conversion CharacterEffect
cUsed to output the category of the logging event. The category conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets.

If a precision specifier is given, then only the corresponding number of right most components of the category name will be printed. By default the category name is printed in full.

For example, for the category name "a.b.c" the pattern %c{2} will output "b.c".

CUsed to output the fully qualified class name of the caller issuing the logging request. This conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets.

If a precision specifier is given, then only the corresponding number of right most components of the class name will be printed. By default the class name is output in fully qualified form.

For example, for the class name "org.apache.xyz.SomeClass", the pattern %C{1} will output "SomeClass".

WARNING Generating the caller class information is slow. Thus, use should be avoided unless execution speed is not an issue.

dUsed to output the date of the logging event. The date conversion specifier may be followed by a date format specifier enclosed between braces. For example,%d{HH:mm:ss,SSS} or %d{dd MMM yyyy HH:mm:ss,SSS}. If no date format specifier is given then ISO8601 format is assumed.

The date format specifier admits the same syntax as the time pattern string of the SimpleDateFormat. Although part of the standard JDK, the performance ofSimpleDateFormat is quite poor.

For better results it is recommended to use the log4j date formatters. These can be specified using one of the strings "ABSOLUTE", "DATE" and "ISO8601" for specifying AbsoluteTimeDateFormatDateTimeDateFormat and respectively ISO8601DateFormat. For example, %d{ISO8601} or %d{ABSOLUTE}.

These dedicated date formatters perform significantly better than SimpleDateFormat.

FUsed to output the file name where the logging request was issued.

WARNING Generating caller location information is extremely slow and should be avoided unless execution speed is not an issue.

lUsed to output location information of the caller which generated the logging event.

The location information depends on the JVM implementation but usually consists of the fully qualified name of the calling method followed by the callers source the file name and line number between parentheses.

The location information can be very useful. However, its generation is extremely slow and should be avoided unless execution speed is not an issue.

LUsed to output the line number from where the logging request was issued.

WARNING Generating caller location information is extremely slow and should be avoided unless execution speed is not an issue.

mUsed to output the application supplied message associated with the logging event.
MUsed to output the method name where the logging request was issued.

WARNING Generating caller location information is extremely slow and should be avoided unless execution speed is not an issue.

nOutputs the platform dependent line separator character or characters.

This conversion character offers practically the same performance as using non-portable line separator strings such as "n", or "rn". Thus, it is the preferred way of specifying a line separator.

pUsed to output the priority of the logging event.
rUsed to output the number of milliseconds elapsed from the construction of the layout until the creation of the logging event.
tUsed to output the name of the thread that generated the logging event.
xUsed to output the NDC (nested diagnostic context) associated with the thread that generated the logging event.
X

Used to output the MDC (mapped diagnostic context) associated with the thread that generated the logging event. The X conversion character must be followed by the key for the map placed between braces, as in %X{clientNumber} where clientNumber is the key. The value in the MDC corresponding to the key will be output.

See MDC class for more details.

%The sequence %% outputs a single percent sign.

 

Ejemplo de Archivo Log4j.properties

 

log4j.rootLogger=DEBUG, CA, RFA

log4j.appender.CA=org.apache.log4j.ConsoleAppender

log4j.appender.CA.layout=org.apache.log4j.PatternLayout

log4j.appender.CA.layout.ConversionPattern=%d %-5p %c [%t] - %m%n

 

2010-11-26 14:46:39,498 DEBUG com.integrador.soporte.MyLogger [main] - lucas no viene

Configurar JAVA_HOME

 

Stage 1. Locate Install Directory

If you already know the install path for the Java or Software Development Kit, go to Stage 2. Otherwise, find the install path by following these instructions:

  1. Unless you changed the install path for the Java Developement Kit during installation, it will be in a directory under C:Program FilesJava. Using Explorer, open the directoryC:Program FilesJava
  2. Inside that path will be one or more subdirectories such as jdk1.5.0_08. If you just installed the Java Development Kit, it will be installed to the newest directory, which you can find by sorting by date. For example, it may be installed in C:Program FilesJavajdk1.5.0_08. This is the install path.

Stage 2. Apply Setting

Once you have identified the JDK install path:

  1. Right click on the My Computer icon on your desktop and select properties
  2. Click the Advanced Tab
  3. Click the Environment Variables button
  4. Under System Variable, click New
  5. Enter the variable name as JAVA_HOME
  6. Enter the variable value as the install path for the Development Kit
  7. Click OK
  8. Click Apply Changes
  9. If you are running Confluence as a EAR/WAR rather than the Standalone, you may need to restart your application server
    This diagram shows setting the JAVA_HOME variable to an install path of c:/j2sdk1.4.2

Cambiar el option a Completion Overwrite.

ir a WINDOW -> PREFERENCES -> JAVA -> EDITOR -> CONTENTASIST -> option Completion overwirte

 

Hotkeys para Eclipse

  • CTRL+L Salta a la Linea
  • CTRL+O Metodos dentro de la clase
  • CTRL+D Borra linea
  • CTRL+7 comenta linea
  • CTRL+SHITF+F Formatea el codigo de la clase
  • CTRL+SHITF+M Agrega import