From 75257cd835ebabc9f408929d9a2878059e052366 Mon Sep 17 00:00:00 2001 From: Ceki Gulcu Date: Fri, 4 Feb 2022 22:31:36 +0100 Subject: [PATCH] add canonical tab --- logback-site/src/site/pages/css/site.css | 42 +- logback-site/src/site/pages/js/dsl.js | 101 +- .../src/site/pages/manual/appenders.html | 1142 ++++++++++++----- .../src/site/pages/templates/header.js | 12 +- logback-site/src/site/pages/templates/left.js | 4 +- 5 files changed, 932 insertions(+), 369 deletions(-) diff --git a/logback-site/src/site/pages/css/site.css b/logback-site/src/site/pages/css/site.css index d2c58a819c..a3467c4d2f 100644 --- a/logback-site/src/site/pages/css/site.css +++ b/logback-site/src/site/pages/css/site.css @@ -188,7 +188,7 @@ p.menu_header { display: block; } -span.asGroovy { +span.canonical { background: #fff; color: #0079C5; font-family: "Comic Sans MS", sans-serif; @@ -201,10 +201,10 @@ span.asGroovy { border-bottom: 2px solid #888; padding: 0px 1em 0px 1em; margin: -4px 4px 0 4px; - float: right; + float: top; } -span.asGroovy:hover { +span.canonical:hover { background: #E0E0EF; cursor: pointer; } @@ -544,3 +544,39 @@ p.menu { .deftitle { font-weight: bold; } + + +/* tab BEGIN ================================= */ +.tab { + overflow: hidden; + border: 1px solid #ccc; + background-color: #f1f1f1; +} + +/* Style the buttons that are used to open the tab content */ +.tab button { + background-color: inherit; + float: left; + border: none; + outline: none; + cursor: pointer; + padding: 14px 16px; + transition: 0.3s; +} + +.tab button:hover { + background-color: #ddd; +} + +.tab button.active { + background-color: #ccc; +} + +/* Style the tab content */ +.tabcontent { + display: none; + padding: 6px 12px; + border: 1px solid #ccc; + border-top: none; +} +/* tab END ================================ */ diff --git a/logback-site/src/site/pages/js/dsl.js b/logback-site/src/site/pages/js/dsl.js index 4fb4baff4d..0f2654abed 100755 --- a/logback-site/src/site/pages/js/dsl.js +++ b/logback-site/src/site/pages/js/dsl.js @@ -1,7 +1,100 @@ -var asGroovyURL='http://logback.qos.ch/translator/dsl/asGroovy'; +//var xml2CanonURL='https://logback.qos.ch/translator/dsl/xml2Canon/asText'; +var xml2CanonURL='/translator/dsl/xml2Canon/asText'; -function asGroovy(id) { +//var xml2CanonURL='http://localhost:8080/translator/dsl/xml2Canon/asText'; + +function canonical(legacyId, canonicalId) { + + var form = document.getElementById('aForm'); + if(form == null) { + form = document.createElement("form"); + document.body.appendChild(form); + } + + $(form).empty(); + form.id = 'aForm'; + + var legacyElement = document.getElementById(legacyId); + + var inner = legacyElement.innerHTML; + //alert("==="+inner); + inner = inner.replace(/
/gi, '');
+    inner = inner.replace(/<\/pre>/gi, '');
+    inner = inner.replace(/</gi, '<');
+    inner = inner.replace(/>/gi, '>');
+    
+    inner = inner.replace(//gi, '');
+    inner = inner.replace(/<\/span>/gi, '');
+    inner = inner.replace(/
/gi, ''); + inner = inner.replace(/ /gi, ''); + inner = inner.replace(//gi, ''); + inner = inner.replace(/<\/b>/gi, ''); + + form.setAttribute("method", "post"); + form.setAttribute("action", xml2CanonURL); + + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("type", "hidden"); + hiddenField.setAttribute("name", "val"); + hiddenField.setAttribute("value", inner); + form.appendChild(hiddenField); + + var postData = $("#aForm").serialize(); + + var canonicalElement = document.getElementById(canonicalId); + + + $.post(xml2CanonURL, postData, function(payload, status) { + payload = '
'+payload+'
' + canonicalElement.innerHTML = payload; + canonicalElement.innerHTML = prettyPrintOne(canonicalElement.innerHTML); + }); + + +} + +// $.ajax({ +// url: xml2CanonURL, +// type: 'POST', +// crossDomain: true, +// headers: {'Referrer-Policy': 'origin-when-cross-origin', +// 'Access-Control-Allow-Origin': '*', +// 'Access-Control-Allow-Credentials': 'true', +// 'Access-Control-Allow-Methods': 'POST, OPTIONS'}, +// //beforeSend: function(xhr){ +// // xhr.setRequestHeader('Access-Control-Allow-Origin', '*'); +// // xhr.setRequestHeader('Access-Control-Allow-Credentials', 'true'); +// // xhr.setRequestHeader('Access-Control-Allow-CredentialsMethods', 'POST'); +// //}, +// //xhrFields: { withCredentials: true }, +// data: inner, +// success: function(res) { +// alert(res); +// } +// +// } ); +// alert("zzzzz"); +// form.submit( function (event) { +// $.ajax({ +// url: xml2CanonURL, +// type: 'POST', +// contents: 'text/plain; charset=UTF-8', +// processData: false, +// dataType: "text", +// data: $(this).serialize(), +// success: function(payload, status) { +// alert(payload); +// } +// }); +// return false; +// //event.preventDefault(); +// }); +// return false; +//} + + +function xxCcanonical(id) { var form = document.getElementById('aForm'); if(form == null) { @@ -10,7 +103,7 @@ function asGroovy(id) { } var p = document.getElementById(id); - var inner = p.innerHTML; + var inner = legacyElementinnerHTML; //alert("==="+inner); inner = inner.replace(/</gi, '<'); inner = inner.replace(/>/gi, '>'); @@ -23,7 +116,7 @@ function asGroovy(id) { inner = inner.replace(/<\/b>/gi, ''); form.setAttribute("method", "post"); - form.setAttribute("action", asGroovyURL); + form.setAttribute("action", xml2CanonURL); var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); diff --git a/logback-site/src/site/pages/manual/appenders.html b/logback-site/src/site/pages/manual/appenders.html index d3add7566f..e46aa35c99 100755 --- a/logback-site/src/site/pages/manual/appenders.html +++ b/logback-site/src/site/pages/manual/appenders.html @@ -1,18 +1,18 @@ - - + + Chapter 4: Appenders - + +
@@ -41,7 +41,7 @@

Chapter 4: Appenders

- +

What is an Appender?

@@ -368,7 +368,20 @@

ConsoleAppender

Example: ConsoleAppender configuration (logback-examples/src/main/resources/chapters/appenders/conf/logback-Console.xml)

-
<configuration>
+  
+  
+  
+
+  
+ + +
+ + +
+
<configuration>
 
   <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
     <!-- encoders are assigned the type
@@ -381,7 +394,15 @@ 

ConsoleAppender

<root level="DEBUG"> <appender-ref ref="STDOUT" /> </root> -</configuration>
+ </configuration> +
+
+ +
+

Requires a server call.

+
+ +

After you have set your current path to the logback-examples directory and set @@ -531,7 +552,16 @@

FileAppender

Example: FileAppender configuration (logback-examples/src/main/resources/chapters/appenders/conf/logback-fileAppender.xml)

-
<configuration>
+   
+   
+ + +
+ +
+
<configuration>
 
   <appender name="FILE" class="ch.qos.logback.core.FileAppender">
     <file>testFile.log</file>
@@ -549,7 +579,13 @@ 

FileAppender

<appender-ref ref="FILE" /> </root> </configuration>
+
+ +
+

Requires a server call.

+
+

After changing the current directory to logback-examples, run this example by launching the following command: @@ -573,7 +609,15 @@

Uniquely named files (by configuration by timestamp (logback-examples/src/main/resources/chapters/appenders/conf/logback-timestamp.xml)

-
<configuration>
+   
+ + +
+ +
+
<configuration>
 
   <!-- Insert the current time formatted as "yyyyMMdd'T'HHmmss" under
        the key "bySecond" into the logger context. This value will be
@@ -592,7 +636,13 @@ 

Uniquely named files (by <root level="DEBUG"> <appender-ref ref="FILE" /> </root> -</configuration>

+ </configuration>
+ + + +
+

Requires a server call.

+

The timestamp element takes two mandatory attributes TimeZone

TimeBasedRollingPolicy (logback-examples/src/main/resources/chapters/appenders/conf/logback-RollingTimeBased.xml)

-
<configuration>
+   
+ + +
+ + +
+ +
<configuration>
   <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
     <file>logFile.log</file>
     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
@@ -1188,6 +1248,11 @@ 
TimeZone
<appender-ref ref="FILE" /> </root> </configuration>
+
+ +
+

Requires a server call.

+

The next configuration sample illustrates the use of RollingFileAppender associated with @@ -1200,7 +1265,16 @@

TimeZone
TimeBasedRollingPolicy (logback-examples/src/main/resources/chapters/appenders/conf/logback-PrudentTimeBasedRolling.xml)

-
<configuration>
+   
+ + +
+ + +
+
<configuration>
   <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
     <!-- Support multiple-JVM writing to the same log file -->
     <prudent>true</prudent>
@@ -1219,7 +1293,11 @@ 
TimeZone
<appender-ref ref="FILE" /> </root> </configuration>
- +
+ +
+

Requires a server call.

+

Size and @@ -1248,7 +1326,16 @@

Size and SizeAndTimeBasedFNATP (logback-examples/src/main/resources/chapters/appenders/conf/logback-sizeAndTime.xml)

-
<configuration>
+  
+  
+ + +
+ +
+
<configuration>
   <appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
     <file>mylog.txt</file>
     <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
@@ -1270,6 +1357,12 @@ 

Size and </root> </configuration>

+
+ +
+

Requires a server call.

+
+

Note the "%i" conversion token in addition to "%d". Both the %i and %d tokens are mandatory. Each time the current log file @@ -1447,7 +1540,17 @@

FixedWindowRollingPolicyExample: Sample configuration of a RollingFileAppender using a FixedWindowRollingPolicy (logback-examples/src/main/resources/chapters/appenders/conf/logback-RollingFixedWindow.xml)

-
<configuration>
+   
+   
+ + +
+ +
+ +
<configuration>
   <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
     <file>test.log</file>
 
@@ -1469,20 +1572,22 @@ 

FixedWindowRollingPolicy </root> </configuration>

+
+ +
+

Requires a server call.

+
-

- Overview of - triggering policies -

+

Overview of triggering policies

-

TriggeringPolicy - implementations are responsible for instructing the - RollingFileAppender when to rollover.

+

TriggeringPolicy + implementations are responsible for instructing the + RollingFileAppender when to rollover.

-

The TriggeringPolicy interface contains only one - method.

+

The TriggeringPolicy interface contains only one + method.

package ch.qos.logback.core.rolling;
 
@@ -1494,11 +1599,11 @@ 

public boolean isTriggeringEvent(final File activeFile, final <E> event); }

-

The isTriggeringEvent() method takes as parameters - the active file and the logging event currently being - processed. The concrete implementation determines whether the - rollover should occur or not, based on these parameters. -

+

The isTriggeringEvent() method takes as parameters + the active file and the logging event currently being + processed. The concrete implementation determines whether the + rollover should occur or not, based on these parameters. +

The most widely-used triggering policy, namely TimeBasedRollingPolicy which also doubles as a @@ -1541,7 +1646,16 @@

SizeBasedTriggeringPolicy (logback-examples/src/main/resources/chapters/appenders/conf/logback-RollingSizeBased.xml)

-
<configuration>
+    
+    
+ + +
+ +
+ +
+

Requires a server call.

+
-
-

Logback Classic

- + +

Logback Classic

+ + +

While logging events are generic in logback-core, within + logback-classic they are always instances of + ILoggingEvent. Logback-classic is nothing more than a + specialized processing pipeline handling instances of + ILoggingEvent. -

While logging events are generic in logback-core, within - logback-classic they are always instances of - ILoggingEvent. Logback-classic is nothing more than a - specialized processing pipeline handling instances of - ILoggingEvent. -

- -

SocketAppender and - SSLSocketAppender + +

SocketAppender and + SSLSocketAppender

- -

The appenders covered thus far are only able to log to local - resources. In contrast, the - SocketAppender is designed to log to a remote - entity by transmitting serialized ILoggingEvent - instances over the wire. When using SocketAppender - logging events on the wire are sent in the clear. However, when - using - SSLSocketAppender, logging events are delivered over - a secure channel.

- -

- The actual type of the serialized event - is LoggingEventVO - which implements the ILoggingEvent - interface. Nevertheless, remote logging is non-intrusive as far as - the logging event is concerned. On the receiving end after - deserialization, the event can be logged as if it were generated - locally. Multiple SocketAppender instances running on - different machines can direct their logging output to a central - log server whose format is fixed. SocketAppender - does not take an associated layout because it sends serialized - events to a remote server. SocketAppender operates - above the Transmission Control Protocol (TCP) layer which - provides a reliable, sequenced, flow-controlled end-to-end octet - stream. Consequently, if the remote server is reachable, then log - events will eventually arrive there. Otherwise, if the remote - server is down or unreachable, the logging events will simply be - dropped. If and when the server comes back up, then event - transmission will be resumed transparently. This transparent - reconnection is performed by a connector thread which periodically - attempts to connect to the server. + +

The appenders covered thus far are only able to log to local + resources. In contrast, the + SocketAppender is designed to log to a remote + entity by transmitting serialized ILoggingEvent + instances over the wire. When using SocketAppender + logging events on the wire are sent in the clear. However, when + using + SSLSocketAppender, logging events are delivered + over a secure channel.

+ +

The actual type of the serialized event is LoggingEventVO + which implements the ILoggingEvent + interface. Nevertheless, remote logging is non-intrusive as far as + the logging event is concerned. On the receiving end after + deserialization, the event can be logged as if it were generated + locally. Multiple SocketAppender instances running on + different machines can direct their logging output to a central + log server whose format is fixed. SocketAppender + does not take an associated layout because it sends serialized + events to a remote server. SocketAppender operates + above the Transmission Control Protocol (TCP) layer which + provides a reliable, sequenced, flow-controlled end-to-end octet + stream. Consequently, if the remote server is reachable, then log + events will eventually arrive there. Otherwise, if the remote + server is down or unreachable, the logging events will simply be + dropped. If and when the server comes back up, then event + transmission will be resumed transparently. This transparent + reconnection is performed by a connector thread which periodically + attempts to connect to the server.

-

Logging events are automatically buffered by the native TCP - implementation. This means that if the link to server is slow but - still faster than the rate of event production by the client, the - client will not be affected by the slow network - connection. However, if the network connection is slower than the - rate of event production, then the client can only progress at the - network rate. In particular, in the extreme case where the network - link to the server is down, the client will be eventually blocked. - Alternatively, if the network link is up, but the server is down, - the client will not be blocked, although the log events will be - lost due to server unavailability. +

Logging events are automatically buffered by the native TCP + implementation. This means that if the link to server is slow but + still faster than the rate of event production by the client, the + client will not be affected by the slow network + connection. However, if the network connection is slower than the + rate of event production, then the client can only progress at the + network rate. In particular, in the extreme case where the network + link to the server is down, the client will be eventually blocked. + Alternatively, if the network link is up, but the server is down, + the client will not be blocked, although the log events will be + lost due to server unavailability.

Even if a SocketAppender is no longer attached to @@ -1660,9 +1778,9 @@

SocketAppender and - - - + + + @@ -1685,8 +1803,7 @@

SocketAppender and

- +
Property NameTypeDescriptionProperty NameTypeDescription
includeCallerData
reconnectionDelayreconnectionDelay Duration @@ -1831,10 +1948,19 @@

Using SimpleSocketServer

and attaches it to the root logger.

-

Example: SocketAppender configuration - (logback-examples/src/main/resources/chapters/appenders/socket/client1.xml)

+

Example: SocketAppender configuration + (logback-examples/src/main/resources/chapters/appenders/socket/client1.xml)

-
<configuration>
+    
+    
+ + +
+ +
+
<configuration>
 	  
   <appender name="SOCKET" class="ch.qos.logback.classic.net.SocketAppender">
     <remoteHost>${host}</remoteHost>
@@ -1848,7 +1974,12 @@ 

Using SimpleSocketServer

</root> </configuration>
- +
+ +
+

Requires a server call.

+
+

Note that in the above configuration scripts the values for the remoteHost, port and @@ -1944,10 +2075,18 @@

Using SimpleSSLSocketServer

example shows the appender configuration needed:

-

Example: SSLSocketAppender configuration - (logback-examples/src/main/resources/chapters/appenders/socket/ssl/client.xml)

+

Example: SSLSocketAppender configuration + (logback-examples/src/main/resources/chapters/appenders/socket/ssl/client.xml)

+ +
+ + +
-
<configuration debug="true">
+    
+
<configuration debug="true">
 	  
   <appender name="SOCKET" class="ch.qos.logback.classic.net.SSLSocketAppender">
     <remoteHost>${host}</remoteHost>
@@ -1966,18 +2105,26 @@ 

Using SimpleSSLSocketServer

</root> </configuration>
- -

Note that, just as in the previous example, the values for - remoteHost, port - are specified using substituted variable keys. Additionally, note - the presence of the ssl property and its - nested trustStore property, which specifies - the location and password of a trust store using substituted - variables. This configuration is necessary because our example - server is using a self-signed certificate. See - Using SSL for more information on - SSL configuration properties for SSLSocketAppender. -

+
+ + +
+

Requires a server call. Please wait a few seconds.

+
+ + +

Note that, just as in the previous example, the values for + remoteHost, port are specified using substituted variable + keys. Additionally, note the presence of the ssl property and its nested trustStore property, which specifies the + location and password of a trust store using substituted + variables. This configuration is necessary because our example + server is using a self-signed certificate. See Using SSL for more information on SSL + configuration properties for SSLSocketAppender. +

We can run a client application using this configuration by specifying the substitution variable values on the command line as @@ -1990,17 +2137,17 @@

Using SimpleSSLSocketServer

chapters.appenders.socket.SocketClient2 src/main/java/chapters/appenders/socket/ssl/client.xml

-

As in the previous examples, you can type in a message when - prompted by the client application, and the message will be delivered - to the logging server (now over a secure channel) where it will be - displayed on the console. -

+

As in the previous examples, you can type in a message when + prompted by the client application, and the message will be + delivered to the logging server (now over a secure channel) where + it will be displayed on the console. +

-

Note that the truststore property given on the command - line specifies a file URL that identifies the location of the - trust store. You may also use a classpath URL as described in Using SSL. -

+

Note that the truststore property given on the + command line specifies a file URL that identifies the location of + the trust store. You may also use a classpath URL as described + in Using SSL. +

As we saw previously at server startup, because the client configuration has debug="true" specified on the root @@ -2104,7 +2251,17 @@

Example: Basic ServerSocketAppender Configuration (logback-examples/src/main/resources/chapters/appenders/socket/server4.xml)

-
<configuration debug="true">
+
+    
+ + +
+ +
+ +
<configuration debug="true">
   <appender name="SERVER" 
     class="ch.qos.logback.classic.net.server.ServerSocketAppender">
     <port>${port}</port>
@@ -2117,6 +2274,13 @@ 

</configuration>

+
+ +
+

Requires a server call. Please wait a few seconds.

+
+ +

Note that this configuration differs from previous examples using SocketAppender only in the class specified for the appender, and in the absence of the remoteHost @@ -2130,7 +2294,17 @@

Example: Basic SSLServerSocketAppender Configuration (logback-examples/src/main/resources/chapters/appenders/socket/ssl/server3.xml)

-
<configuration debug="true">
+
+    
+ + +
+ +
+ +
<configuration debug="true">
   <appender name="SERVER" 
     class="ch.qos.logback.classic.net.server.SSLServerSocketAppender">
     <port>${port}</port>
@@ -2149,7 +2323,12 @@ 

</configuration>

- +
+ +
+

Requires a server call. Please wait a few seconds.

+
+

The principal differences between this configuration and the previous configuration is that the appender's class attribute identifies the SSLServerSocketAppender type, and the @@ -2178,9 +2357,9 @@

SMTPAppender

The various properties for SMTPAppender are summarized in the following table. -

+

- +
@@ -2492,7 +2671,17 @@

SMTPAppender

Example: A sample SMTPAppender configuration (logback-examples/src/main/resources/chapters/appenders/mail/mail1.xml)

-
<configuration>	  
+    
+    
+ + +
+ +
+ +
<configuration>	  
   <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
     <smtpHost>ADDRESS-OF-YOUR-SMTP-HOST</smtpHost>
     <to>EMAIL-DESTINATION</to>
@@ -2508,32 +2697,40 @@ 

SMTPAppender

<appender-ref ref="EMAIL" /> </root> </configuration>
+
-

Before trying out chapters.appenders.mail.Email application - with the above configuration file, you must set the smtpHost, to and - from properties to values appropriate for - your environment. Once you have set the correct values in the - configuration file, execute the following command: -

+ +
+

Requires a server call. Please wait a few seconds.

+
+ + +

Before trying out chapters.appenders.mail.Email + application with the above configuration file, you must set the + smtpHost, to + and from properties to values + appropriate for your environment. Once you have set the correct + values in the configuration file, execute the following command: +

-
java chapters.appenders.mail.EMail 100 src/main/java/chapters/appenders/mail/mail1.xml
+
java chapters.appenders.mail.EMail 100 src/main/java/chapters/appenders/mail/mail1.xml
-

The recipient you specified should receive an email message - containing 100 logging events formatted by - PatternLayout The figure below is the resulting email - message as shown by Mozilla Thunderbird. +

The recipient you specified should receive an email message + containing 100 logging events formatted by + PatternLayout The figure below is the resulting email + message as shown by Mozilla Thunderbird.

resulting email

-

In the next example configuration file mail2.xml, the - values for the smtpHost, to and from - properties are determined by variable substitution. Here is the - relevant part of mail2.xml. +

In the next example configuration file mail2.xml, the + values for the smtpHost, to and from + properties are determined by variable substitution. Here is the + relevant part of mail2.xml.

+
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
   <smtpHost>${smtpHost}</smtpHost>
   <to>${to}</to>
@@ -2541,22 +2738,22 @@ 

SMTPAppender

<layout class="ch.qos.logback.classic.html.HTMLLayout"/> </appender>
-

You can pass the required parameters on the command line:

+

You can pass the required parameters on the command line:

-
java -Dfrom=source@xyz.com -Dto=recipient@xyz.com -DsmtpHost=some_smtp_host \
+    
java -Dfrom=source@xyz.com -Dto=recipient@xyz.com -DsmtpHost=some_smtp_host \
   chapters.appenders.mail.EMail 10000 src/main/java/chapters/appenders/mail/mail2.xml
 
-

Be sure to replace with values as appropriate for your - environment. -

+

Be sure to replace with values as appropriate for your + environment. +

-

Note that in this latest example, PatternLayout - was replaced by HTMLLayout which formats logs as an - HTML table. You can change the list and order of columns as well - as the CSS of the table. Please refer to HTMLLayout documentation - for further details. +

Note that in this latest example, PatternLayout + was replaced by HTMLLayout which formats logs as an + HTML table. You can change the list and order of columns as well + as the CSS of the table. Please refer to HTMLLayout documentation + for further details.

Given that the size of the cyclic buffer is 256, the recipient @@ -2591,7 +2788,18 @@

Custom buffer

Example: SMTPAppender configuration with a custom bufer size (logback-examples/src/main/resources/chapters/appenders/mail/customBufferSize.xml)

-
<configuration>   
+
+   
+   
+ + +
+ +
+ +
<configuration>   
   <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
     <smtpHost>${smtpHost}</smtpHost>
     <to>${to}</to>
@@ -2609,8 +2817,13 @@ 

Custom buffer <appender-ref ref="EMAIL" /> </root> </configuration>

- +
+ +
+

Requires a server call. Please wait a few seconds.

+
+

Triggering event

If the Evaluator property is not set, the @@ -2623,22 +2836,24 @@

Triggering event

implementation of the EventEvaluator interface.

-

The SMTPAppender submits each incoming event to - its evaluator by calling evaluate() method in order - to check whether the event should trigger an email or just be - placed in the cyclic buffer. When the evaluator gives a positive - answer to its evaluation, an email is sent out. The - SMTPAppender contains one and only one evaluator - object. This object may manage its own internal state. For - illustrative purposes, the CounterBasedEvaluator - class listed next implements an event evaluator whereby every - 1024th event triggers an email message. -

+

The SMTPAppender submits each incoming event to + its evaluator by calling evaluate() method in order + to check whether the event should trigger an email or just be + placed in the cyclic buffer. When the evaluator gives a positive + answer to its evaluation, an email is sent out. The + SMTPAppender contains one and only one evaluator + object. This object may manage its own internal state. For + illustrative purposes, the CounterBasedEvaluator + class listed next implements an event evaluator whereby every + 1024th event triggers an email message. +

-

Example: A EventEvaluator implementation -that evaluates to true every 1024th event (logback-examples/src/main/java/chapters/appenders/mail/CounterBasedEvaluator.java)

- -
package chapters.appenders.mail;
+    

Example: A EventEvaluator + implementation that evaluates to true every 1024th + event (logback-examples/src/main/java/chapters/appenders/mail/CounterBasedEvaluator.java)

+ +
package chapters.appenders.mail;
 
 import ch.qos.logback.core.boolex.EvaluationException;
 import ch.qos.logback.core.boolex.EventEvaluator;
@@ -2672,25 +2887,34 @@ 

Triggering event

} }
-

Note that this class extends ContextAwareBase and - implements EventEvaluator. This allows the user to - concentrate on the core functions of her - EventEvaluator and let the base class provide the - common functionality. -

+

Note that this class extends ContextAwareBase + and implements EventEvaluator. This allows the + user to concentrate on the core functions of her + EventEvaluator and let the base class provide the + common functionality. +

-

Setting the Evaluator option of - SMTPAppender instructs it to use a custom evaluator. - The next configuration file attaches a SMTPAppender - to the root logger. This appender uses a - CounterBasedEvaluator instance as its event - evaluator. -

+

Setting the Evaluator option of + SMTPAppender instructs it to use a custom evaluator. + The next configuration file attaches a SMTPAppender + to the root logger. This appender uses a + CounterBasedEvaluator instance as its event + evaluator. +

Example: SMTPAppender with custom Evaluator and buffer size (logback-examples/src/main/resources/chapters/appenders/mail/mail3.xml)

-
<configuration>
+    
+ + +
+ +
+ +
<configuration>
   <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
     <evaluator class="chapters.appenders.mail.CounterBasedEvaluator" />
     <smtpHost>${smtpHost}</smtpHost>
@@ -2705,7 +2929,13 @@ 

Triggering event

<appender-ref ref="EMAIL" /> </root> </configuration>
+
+ +
+

Requires a server call. Please wait a few seconds.

+
+

Marker based triggering

@@ -2740,8 +2970,16 @@

Marker based

Example: SMTPAppender with OnMarkerEvaluator (logback-examples/src/main/resources/chapters/appenders/mail/mailWithMarker.xml)

+
+ + +
+ +
-
<configuration>
+   
<configuration>
   <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
     <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
       <marker>NOTIFY_ADMIN</marker>
@@ -2759,6 +2997,11 @@ 

Marker based <appender-ref ref="EMAIL" /> </root> </configuration>

+
+ +
+

Requires a server call. Please wait a few seconds.

+

Give it a whirl with the following command:

@@ -2766,8 +3009,9 @@

Marker based chapters.appenders.mail.Marked_EMail src/main/java/chapters/appenders/mail/mailWithMarker.xml

-

Marker-based - triggering with JaninoEventEvaluator

+

Marker-based triggering with + JaninoEventEvaluator

Note that instead of using the marker-centric OnMarkerEvaluator, we could use the much more generic @@ -2784,17 +3028,35 @@

Marker-based

Example: SMTPAppender with JaninoEventEvaluator (logback-examples/src/main/resources/chapters/appenders/mail/mailWithMarker_Janino.xml)

-
<configuration>
+   
+ + +
+ +
+ +
<configuration>
   <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
     <evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
       <expression>
         (marker != null) &&
         (marker.contains("NOTIFY_ADMIN") || marker.contains("TRANSACTION_FAILURE"))
       </expression>
-    </evaluator>    
-    ... same as above
+    </evaluator>
+    <smtpHost>${smtpHost}</smtpHost>
+    <to>${to}</to>
+    <from>${from}</from>
+    <layout class="ch.qos.logback.classic.html.HTMLLayout"/>
   </appender>
 </configuration>
+
+ +
+

Requires a server call. Please wait a few seconds.

+
+

Marker-based triggering with GEventEvaluator

@@ -2805,6 +3067,15 @@

Marker-based

Example: the same with GEventEvaluator (logback-examples/src/main/resources/chapters/appenders/mail/mailWithMarker_GEvent.xml)

+ +
+ + +
+ +
<configuration>
   <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
@@ -2812,10 +3083,24 @@ 

Marker-based <expression> e.marker?.contains("NOTIFY_ADMIN") || e.marker?.contains("TRANSACTION_FAILURE") </expression> - </evaluator> - ... same as above + </evaluator> + <smtpHost>${smtpHost}</smtpHost> + <to>${to}</to> + <from>${from}</from> + <layout class="ch.qos.logback.classic.html.HTMLLayout"/> </appender> </configuration>

+
+ +
+

Requires a server call. Please wait a few seconds.

+
+ + + +
+

Requires a server call. Please wait a few seconds.

+

Note that since the event may lack a marker, the value of e.marker can be null. Hence the use of Groovy's SMTPAppender configuration

Example:: SMTPAppender to Gmail using SSL (logback-examples/src/main/resources/chapters/appenders/mail/gmailSSL.xml)

+ +
+ + +
+ +
<configuration>
   <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
@@ -2866,8 +3160,12 @@ 

SMTPAppender configuration <appender-ref ref="EMAIL" /> </root> </configuration>

+
- +
+

Requires a server call. Please wait a few seconds.

+
+

SMTPAppender for Gmail (STARTTLS)

@@ -2877,6 +3175,15 @@

SMTPAppender for Gmail

Example: SMTPAppender to GMAIL using STARTTLS (logback-examples/src/main/resources/chapters/appenders/mail/gmailSTARTTLS.xml)

+
+ + +
+ +
+
<configuration>	  
   <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
     <smtpHost>smtp.gmail.com</smtpHost>
@@ -2898,7 +3205,12 @@ 

SMTPAppender for Gmail <appender-ref ref="EMAIL" /> </root> </configuration>

+
+ +
+

Requires a server call. Please wait a few seconds.

+

SMTPAppender with MDCDiscriminator

@@ -2922,7 +3234,16 @@

SMTPAppender with MDCDiscriminator MDCBasedDsicriminator (logback-examples/src/main/resources/chapters/appenders/mail/mailWithMDCBasedDiscriminator.xml)

-
<configuration>	  
+    
+ + +
+ +
+ +
<configuration>	  
   <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
     <smtpHost>ADDRESS-OF-YOUR-SMTP-HOST</smtpHost>
     <to>EMAIL-DESTINATION</to>
@@ -2944,6 +3265,12 @@ 

SMTPAppender with MDCDiscriminator <appender-ref ref="EMAIL" /> </root> </configuration>

+
+ +
+

Requires a server call. Please wait a few seconds.

+
+

Thus, each outgoing email generated by SMTPAppender will belong to a unique remote @@ -3313,7 +3640,16 @@

ConnectionSource

Example: DBAppender configuration (logback-examples/src/main/resources/chapters/appenders/db/append-toMySQL-with-driverManager.xml)

-
<configuration>
+    
+ + +
+ +
+ +
<configuration>
 
   <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
     <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
@@ -3328,32 +3664,35 @@ 

ConnectionSource

<appender-ref ref="DB" /> </root> </configuration>
+
-

- The correct driver must be declared. Here, the com.mysql.jdbc.Driver - class is used. The url must begin with jdbc:mysql://. -

- -

- The - - DriverManagerConnectionSource is an implementation of - ConnectionSource that obtains the connection in the - traditional JDBC manner based on the connection URL. -

-

- Note that this class will establish a new - Connection for each call to - getConnection(). It is recommended that you either - use a JDBC driver that natively supports connection pooling or - that you create your own implementation of - ConnectionSource that taps into whatever pooling - mechanism you are already using. If you have access to a JNDI - implementation that supports javax.sql.DataSource, - e.g. within a J2EE application server, see JNDIConnectionSource - below. -

+
+

Requires a server call. Please wait a few seconds.

+
+ +

The correct driver must be declared. Here, the + com.mysql.jdbc.Driver class is used. The url must begin with jdbc:mysql://. +

+ +

The + DriverManagerConnectionSource is an + implementation of ConnectionSource that obtains the + connection in the traditional JDBC manner based on the connection + URL.

+ +

Note that this class will establish a new + Connection for each call to + getConnection(). It is recommended that you either + use a JDBC driver that natively supports connection pooling or + that you create your own implementation of + ConnectionSource that taps into whatever pooling + mechanism you are already using. If you have access to a JNDI + implementation that supports javax.sql.DataSource, + e.g. within a J2EE application server, see JNDIConnectionSource + below.

Property Name Type