-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added an example of using the SSL enabled components
- Loading branch information
Showing
6 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
logback-examples/src/main/java/chapters/appenders/socket/ssl/SocketClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2011, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package chapters.appenders.socket.ssl; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import ch.qos.logback.classic.LoggerContext; | ||
import ch.qos.logback.classic.joran.JoranConfigurator; | ||
|
||
|
||
/** | ||
* This application uses an SSLSocketAppender that log messages to a | ||
* server on a host and port specified by the user. It waits for the | ||
* user to type a message which will be sent to the server. | ||
* */ | ||
public class SocketClient { | ||
static void usage(String msg) { | ||
System.err.println(msg); | ||
System.err.println("Usage: java " + SocketClient.class.getName() + | ||
" configFile\n" + | ||
" configFile a logback configuration file" + | ||
" in XML format."); | ||
System.exit(1); | ||
} | ||
|
||
static public void main(String[] args) throws Exception { | ||
if (args.length != 1) { | ||
usage("Wrong number of arguments."); | ||
} | ||
|
||
String configFile = args[0]; | ||
|
||
if (configFile.endsWith(".xml")) { | ||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); | ||
JoranConfigurator configurator = new JoranConfigurator(); | ||
lc.stop(); | ||
configurator.setContext(lc); | ||
configurator.doConfigure(configFile); | ||
} | ||
|
||
Logger logger = LoggerFactory.getLogger(SocketClient.class); | ||
|
||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
while (true) { | ||
System.out.println( | ||
"Type a message to send to log server. Type 'q' to quit."); | ||
|
||
String s = reader.readLine(); | ||
|
||
if (s.equals("q")) { | ||
break; | ||
} else { | ||
logger.debug(s); | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
logback-examples/src/main/java/chapters/appenders/socket/ssl/SocketServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2011, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package chapters.appenders.socket.ssl; | ||
|
||
import org.slf4j.LoggerFactory; | ||
|
||
import ch.qos.logback.classic.LoggerContext; | ||
import ch.qos.logback.classic.joran.JoranConfigurator; | ||
|
||
|
||
/** | ||
* This application uses an SSLSocketServer that log messages to a | ||
* server on a host and port specified by the user. It waits for the | ||
* user to type a message which will be sent to the server. | ||
* */ | ||
public class SocketServer { | ||
static void usage(String msg) { | ||
System.err.println(msg); | ||
System.err.println("Usage: java " + SocketServer.class.getName() + | ||
" configFile\n" + | ||
" configFile a logback configuration file" + | ||
" in XML format."); | ||
System.exit(1); | ||
} | ||
|
||
static public void main(String[] args) throws Exception { | ||
if (args.length != 1) { | ||
usage("Wrong number of arguments."); | ||
} | ||
|
||
String configFile = args[0]; | ||
|
||
if (configFile.endsWith(".xml")) { | ||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); | ||
JoranConfigurator configurator = new JoranConfigurator(); | ||
lc.stop(); | ||
configurator.setContext(lc); | ||
configurator.doConfigure(configFile); | ||
} | ||
|
||
Thread.sleep(Long.MAX_VALUE); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
logback-examples/src/main/java/chapters/appenders/socket/ssl/client.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<!-- ==================================================================== --> | ||
<!-- Sample SSLSocketAppender configuration. --> | ||
<!-- ==================================================================== --> | ||
|
||
<configuration debug="true"> | ||
|
||
<appender name="SOCKET" class="ch.qos.logback.classic.net.SSLSocketAppender"> | ||
<remoteHost>${host}</remoteHost> | ||
<port>${port}</port> | ||
<reconnectionDelay>10000</reconnectionDelay> | ||
<ssl> | ||
<trustStore> | ||
<location>${truststore}</location> | ||
<passphrase>${passphrase}</passphrase> | ||
</trustStore> | ||
</ssl> | ||
</appender> | ||
|
||
<root level="debug"> | ||
<appender-ref ref="SOCKET" /> | ||
</root> | ||
|
||
</configuration> | ||
|
||
|
||
|
Binary file added
BIN
+2.12 KB
logback-examples/src/main/java/chapters/appenders/socket/ssl/keystore.jks
Binary file not shown.
32 changes: 32 additions & 0 deletions
32
logback-examples/src/main/java/chapters/appenders/socket/ssl/server.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<!-- ==================================================================== --> | ||
<!-- Sample SSLSocketServer configuration. --> | ||
<!-- ==================================================================== --> | ||
|
||
<configuration debug="true"> | ||
|
||
<server class="ch.qos.logback.classic.net.server.SSLSocketServer"> | ||
<port>${port}</port> | ||
<ssl> | ||
<keyStore> | ||
<location>${keystore}</location> | ||
<passphrase>${passphrase}</passphrase> | ||
</keyStore> | ||
</ssl> | ||
</server> | ||
|
||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="debug"> | ||
<appender-ref ref="CONSOLE" /> | ||
</root> | ||
|
||
</configuration> | ||
|
||
|
||
|
Binary file added
BIN
+861 Bytes
logback-examples/src/main/java/chapters/appenders/socket/ssl/truststore.jks
Binary file not shown.