[logback-user] SimpleServerSocket

José Laredo López joselaredo at gmail.com
Fri Nov 8 13:14:10 CET 2013


Hi,

I'm trying to connect to a SimpleServerSocket like the example in the
documentation with a SocketAppender. If I send messages continuosly, the
server don't receive the messages. If the client programs sends the
messages with a sleep, the server receives the message correctly. Can you
help me?.

This is the code and the configuration file:

Client program:

/*
 * To change this license header, choose License Headers in Project
Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package logbackc;

import java.util.ArrayList;
import java.util.Date;
import java.util.Random;
import java.util.logging.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogBackC {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws InterruptedException {

        Logger logger = LoggerFactory.getLogger("ABCDEF");
        Integer th = 1;
        Integer pe = 100;

        Random r = new Random();
        for (int i = 0; i < pe; i++) {
            Integer num = r.nextInt(10);
            Boolean war = r.nextBoolean();
            String message= "ABCDEF-" + (war ? "W" : "E") +"-"+ num;
            logger.info("{} {} {}",message, th, i);

        }
    }
}

Client config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <property name="HOSTNAME" value="127.0.0.1" />
    <property name="PORT" value="6000" />

    <appender name="SOCKET"
class="ch.qos.logback.classic.net.SocketAppender">
        <remoteHost>${HOSTNAME}</remoteHost>
        <port>${PORT}</port>
        <reconnectionDelay>10000</reconnectionDelay>
        <includeCallerData>false</includeCallerData>
    </appender>

    <root level="INFO">
        <appender-ref ref="SOCKET" />
    </root>

</configuration>

Server config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>testFile.log</file>
    <append>true</append>
    <encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
  </appender>

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






Thank you very much
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20131108/d9220d91/attachment.html>


More information about the Logback-user mailing list