The document provides an overview of Log4j, an open source logging library for Java. It discusses Log4j's core features including log levels, appenders, loggers, and layouts. Log levels determine which log messages are output, appenders define output destinations, loggers control which statements are logged, and layouts customize output formats. The document also provides configuration examples for common appenders like files, emails, and databases.
12. Appenders Configuration Example <appender name="FileAppender" class=" org.apache.log4j.FileAppender "> <param name=" File " value="/log/myFile.log" /> <param name=" Append " value="true" /> <param name=" Threshold " value="INFO"/> . . . </appender> FileAppenders: Appends log events to a file. File : path and filename of the file. Append : If true, open the file in append mode. If false, open in truncate mode. Threshold : Set the threshold level. All log events with lower level than the threshold level are ignored by the appender. (TRACE, DEBUG, INFO, WARN, ERROR and FATAL) ImmediateFlush : Default is true, meaning log messages are not buffered at all which is what you want almost all of the time.
13. <appender name="RollingFileSample" class=" org.apache.log4j.RollingFileAppender "> <param name="File" value="/log/myRollingFile.log"/> <param name="Append" value="true"/> <param name=" MaxFileSize " value="500KB"/> <param name=" MaxBackupIndex " value="1"/> . . . </appender> RollingFileAppenders: Extends FileAppender to backup the log files when they reach a certain size . MaxFileSize : Set the maximum size that the output file is allowed to reach before being rolled over to backup files. You can specify the value with the suffixes "KB","MB" or "GB“. MaxBackupIndex : Set the maximum number of backup files to keep around. 0 means no backup files at all. * Plus all parameters from fileAppender
14. <appender name="DRFileSample" class=" org.apache.log4j.DailyRollingFileAppender "> <param name="File" value="/log/myDailyFile.log"/> <param name="DatePattern" value="'.'yyyy-MM-dd'.log'"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/> </layout> </appender> DailyRollingFileAppender: Extends FileAppender so that the underlying file is rolled over at a user chosen frequency. DatePattern : Takes a string in the same format as expected by SimpleDateFormat . This options determines the rollover schedule. Ex: DatePattern Rollover schedule '.'yyyy-MM' Rollover at the beginning of each month '.'yyyy-MM-dd' Rollover at midnight each day. '.'yyyy-MM-dd-HH' Rollover at the top of every hour. where '.' represent your filename in the datePattern * Plus all parameters from fileAppender
15. <appender name="CONSOLE" class=" org.apache.log4j.ConsoleAppender "> <param name=" Target " value="System.out"/> <param name=" Threshold " value="INFO"/> . . . </appender> ConsoleAppender: appends log events to System.out or System.err using a layout specified by the user. The default target is System.out. Target : Recognized values are "System.out" and "System.err". Any other value will be ignored. Threshold : TRACE, DEBUG, INFO, WARN, ERROR and FATAL. ImmediateFlush : Default is true, meaning log messages are not buffered at all which is what you want almost all of the time.
16. <appender name="JDBCSample" class=" org.apache.log4j.jdbc.JDBCAppender "> <param name=" Threshold " value="ERROR"/> <param name=" driver " value="com.sybase.jdbc2.jdbc.SybDriver"/> <param name=" URL " value="jdbc:sybase:Tds:127.0.0.1:2638/Summit"/> <param name=" user " value="DBA"/> <param name=" password " value="SQL"/> . . . </appender> JDBCAppender: sending log events to a database. Driver : Ensures that the given driver class has been loaded for SQL connection creation. URL : url / jdbc connection. user : Connection username. password : Connection username. Threshold : TRACE, DEBUG, INFO, WARN, ERROR and FATAL.
17. <appender name="EmailSample" class=" org.apache.log4j.net.SMTPAppender "> <param name=" Threshold " value="FATAL"/> <param name=" To " value="name@email.com"/> <param name=" From " value="name@email.com"/> <param name=" Subject " value="One Fatal Error"/> <param name=" SMTPHost " value="localhost"/> <param name=" BufferSize " value="10"/> . . . </appender> SMTPAppender: Send an e-mail when a specific logging event occurs. To, From : takes a string value which should be a comma separated list of e-mail address of the recipients / sender. Cc, Bcc : the cc and bcc recipient addresses. Subject : the subject of the e-mail message. SMTHHost : the host name of the SMTP server that will send the e-mail message. SMTHUsername : the username required to authenticate against the mail server. SMTHPassword : the password required to authenticate against the mail server. BufferSize : the maximum number of logging events to collect in a cyclic buffer. Threshold : TRACE, DEBUG, INFO, WARN, ERROR and FATAL.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29. XMLLayout - org.apache.log4j.xml.XMLLayout The output of the XMLLayout consists of a series of log4j:event elements as defined in the log4j.dtd. It does not output a complete well-formed XML file. The output is designed to be included as an external entity in a separate file to form a correct XML file. For example, if abc is the name of the faile where the XMLLayout output goes, then a well-formed XML file would be: <log4j:event logger="com.ing.canada.myPackage.MyClass" timestamp="1165519924224" level="FATAL" thread="Servlet.Engine.Transports : 0"> <log4j:message> <![CDATA[TEST FATAL. debug]]> </log4j:message> </log4j:event>
30. HTMLLayout - org.apache.log4j.HTMLLayout This layout outputs events in a HTML table. <body bgcolor="#FFFFFF" topmargin="6" leftmargin="6"> <hr size="1" noshade> Log session start time Thu Dec 07 15:03:00 EST 2006<br><br> <table cellspacing="0" cellpadding="4" border="1" bordercolor="#224466" width="100%"> <tr> <th>Time</th><th>Thread</th><th>Level</th><th>Category</th> <th>File:Line</th><th>Message</th> </tr> <tr> <td>16</td> <td title="Servlet.Engine.Transports : 0 thread">Servlet.Engine.Transports : 0</td> <td title="Level"><font color="#993300"><strong>FATAL</strong></font></td> <td title="com.ing.canada.autoquote.filter.SessionAttributesFiltercategory"> com.ing.canada.autoquote.filter.SessionAttributesFilter </td> <td>SessionAttributesFilter.java:66</td> <td title="Message">TEST FATAL. debug</td> </tr>
31. Layout Configuration Example <layout class="org.apache.log4j. PatternLayout "> <param name=" ConversionPattern " value="%d %-5p [%c] %m%n"/> </layout> <layout class="org.apache.log4j.xml. XMLLayout "> <param name=" LocationInfo " value="true" /> </layout> <layout class="org.apache.log4j. HTMLLayout "> <param name="LocationInfo" value="true" /> <param name=" Title " value=“Html Title" /> </layout> ConvesionPattern : This is the string which controls formatting and consists of a mix of literal content and conversion specifiers. LocationInfo : If the the option is set to true, then the file name and line number of the statement at the origin of the log statement will be output. Default is false. Title : This option sets the document title of the generated HTML document.
32.
33.
34. LevelMatchFilter The filter admits two options LevelToMatch and AcceptOnMatch. LevelToMatch: TRACE, DEBUG, INFO, WARN, ERROR or FATAL AcceptOnMatch: If acceptOnMatch is set to true (default) and the level match the criteria all others filters will not be execute and the message will be accepted. Otherwise the message is rejected and passed to the next filter. <filter class=" org.apache.log4j.varia.LevelMatchFilter "> <param name=" LevelToMatch " value="INFO"/> <param name=" AcceptOnMatch " value="true"/> </filter> Filter based on level matching .
35. LevelRangeFilter The filter admits three options LevelMin, LevelMax and AcceptOnMatch. LevelMin: TRACE, DEBUG, INFO, WARN, ERROR or FATAL LevelMin: TRACE, DEBUG, INFO, WARN, ERROR or FATAL AcceptOnMatch: If acceptOnMatch is set to true (default) and the level match the criteria all others filters will not be execute and the message will be accepted. Otherwise the message is rejected and passed to the next filter. <filter class=" org.apache.log4j.varia.LevelRangeFilter "> <param name=" LevelMin " value="DEBUG"/> <param name=" LevelMax " value="ERROR"/> <param name=" AcceptOnMatch " value="true"/> </filter> Filter based on level matching, which can be used to reject messages with priorities outside a certain range (inclusive).
36. StringMatchFilter The filter admits two options StringToMatch and AcceptOnMatch. StringToMatch: String to find in the message AcceptOnMatch: If acceptOnMatch is set to true (default) and the level match the criteria all others filters will not be execute and the message will be accepted. Otherwise the message is rejected and passed to the next filter. <filter class=" org.apache.log4j.varia.StringMatchFilter "> <param name=" StringToMatch " value="1" /> <param name=" AcceptOnMatch " value="true" /> </filter> Filter based on string matching (Case sensitive) .
37. DenyAllFilter You can add this filter to the end of a filter chain to switch from the default "accept all unless instructed otherwise" filtering behaviour to a "deny all unless instructed otherwise" behaviour. <filter class=" org.apache.log4j.varia.DenyAllFilter "/> This filter drops all logging events.
38.
39.
40.
Hinweis der Redaktion
Le nom du POJO correspond, par défaut, au nom de la table. Le nom des membres du POJO correspondent, par défaut, aux noms des champs de la table. @Id on peut spécifier une stratégie de génération de ID (default == non générée) - @GeneratedValue(strategy=GenerationType.AUTO) - @GeneratedValue(strategy=GenerationType.TABLE) - @GeneratedValue(strategy=GenerationType.SEQUENCE) - @GeneratedValue(strategy=GenerationType.IDENTITY)
Par défaut, dans une relation, le join column sera formé de la sorte: <source_relationship_name>_<target_pk_name> Donc ici: D_ID
Ici le propriétaire de la relation est Employee, c’est lui qui a la foreign key. Donc ParkingSpace a seulement besoin de spécifier sur quel champs la relation est mappé dans la classe propriétaire de la relation. Si la FK == PK, on peut utiliser @PrimaryKeyJoinColumn au lieu de @JoinColumn(name= …) Dans une relation bidirectionnelle, une seule des entité « possède » la relation. L’entité propriétaire de la relation est celle qui déclare la « join column ».
Ici le propriétaire de la relation est Employee, c’est lui qui a la foreign key. Donc ParkingSpace a seulement besoin de spécifier sur quel champs la relation est mappé dans la classe propriétaire de la relation. Si la FK == PK, on peut utiliser @PrimaryKeyJoinColumn au lieu de @JoinColumn(name= …) Dans une relation bidirectionnelle, une seule des entité « possède » la relation. L’entité propriétaire de la relation est celle qui déclare la « join column ».