how can i get "ch.qos.logback.classic.Logger" ?

577 views
Skip to first unread message

조현우

unread,
Aug 26, 2014, 5:06:59 AM8/26/14
to ve...@googlegroups.com
Hi.
asking again. sorry;

i want to get a logback in my class for logger.
so, 

1. add jar into my lib

- logback-classic-1.1.2.jar

- logback-core-1.1.2.jar

- slf4j-api-1.7.7.jar


2-1. add configure in vertx.sh

-Dorg.vertx.logger-delegate-factory-class-name=org.vertx.java.core.logging.impl.SLF4JLogDelegateFactory


2-2. edit config file setting

-Djava.util.logging.config.file=${VERTX_JUL_CONFIG:-${VERTX_HOME}/conf/logback.xml}


3. set logback.xml file.

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

<configuration scan="true">


    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">

        <layout class="ch.qos.logback.classic.PatternLayout">

            <Pattern>%d{HH:mm:ss.SSS} %-5level%msg%n</Pattern> <!-- %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n -->

        </layout>

    </appender>

    <appender name="FILE" class="ch.qos.logback.core.FileAppender">

        <file>/Users/jogun/Documents/vertx/.logs/output.log</file>

        <layout class="ch.qos.logback.classic.PatternLayout">

            <Pattern>%d{HH:mm:ss.SSS} %-5level%msg%n</Pattern>

        </layout>

    </appender>


    <logger name="com.tmon.collector" level="INFO"/>


    <root level="INFO">

        <appender-ref ref="STDOUT" />

        <appender-ref ref="FILE" />

    </root>

</configuration>




but, in my code

my logger is org.apache.commons.logging

i need ch.qos.logback.classic.Logger for multi log file. (addAppender(), getAppender() so on...)


please help.








Alexander Lehmann

unread,
Aug 26, 2014, 7:20:40 AM8/26/14
to ve...@googlegroups.com
how are you running your vertx program? I think I got this working a while back, but I'm not sure what I did in the end.

The vertx logger supports jul, log4j and slf4j out of the box, apache commons logging is not used I thnk.

(usually a small sample program is helpful, if you can create a sample project that contains just the code to exhibit the issue, you could put that up on github, dropbox or whatever is convenient for you).

Alexander Lehmann

unread,
Aug 26, 2014, 4:16:51 PM8/26/14
to ve...@googlegroups.com
Found my project, the verticle is just the following class:

import org.vertx.java.core.logging.Logger;
import org.vertx.java.platform.Verticle;

public class Logtest extends Verticle {
 
public void start() {
   
Logger logger=container.logger();
    logger
.info("starting verticle");
 
}
}

put slf4japi-1.7.7, logback-classic-1.1.2 and logback-core.1.1.2 into the lib directory of your vertx installation and run the program with

export VERTX_OPTS=-Dorg.vertx.logger-delegate-factory-class-name=org.vertx.java.core.logging.impl.SLF4JLogDelegateFactory
vertx run
Logtest.java

22:12:09.562 [vert.x-worker-thread-0] DEBUG o.v.j.p.impl.DefaultPlatformManager - Deploying name : deployment-eb3141c6-8c7a-487e-a7bf-f0e30db6fe14 main: Logtest.java instances: 1
22:12:10.110 [vert.x-eventloop-thread-1] INFO  null-Logtest.java-1155328461 - starting verticle
22:12:10.112 [vert.x-eventloop-thread-0] INFO  o.v.java.platform.impl.cli.Starter - Succeeded in deploying verticle

Maciej Żerkowski

unread,
Oct 24, 2014, 5:04:26 PM10/24/14
to ve...@googlegroups.com
And how to achieve similar with using fat jars?

Alexander Lehmann

unread,
Oct 25, 2014, 7:02:44 AM10/25/14
to ve...@googlegroups.com
Put the three jars into src/main/resources/platform_lib, then they will end up in platform_lib of the mod in the fatjar.

Not sure how to get that done inside maven, I just added the files directly to the project. 

I can put up my sample project if you like.

Maciej Żerkowski

unread,
Oct 25, 2014, 7:43:14 AM10/25/14
to ve...@googlegroups.com
The thing is that in my fatJar I have both my own modules and other modules like mod-jdbc-persistor for example and when I setup Logback it works fine for my modules where I have my logger defined but it does not work for mentioned one for example where it uses  BusModBase.logger and all errors are being logged on console only, whereas they should go as my logs to the file as configured in logback.xml.
I asked the same question here: https://groups.google.com/forum/#!searchin/vertx/logback|sort:relevance/vertx/Mh7nIHru1Zk/96L6M0bi404J but no answer so far:(

Alexander Lehmann

unread,
Oct 25, 2014, 8:27:34 AM10/25/14
to ve...@googlegroups.com
If the modules are in fact using logback via the delegate, they are probably not finding the config file. I'm not sure how this works, maybe you have to put the logback.xml into resources/platform_lib as well or put it into either into the root of the farjar or into a classpath dir when starting the jar (which would kind of spoil the idea of a fatjar).

Maciej Żerkowski

unread,
Oct 25, 2014, 9:16:52 AM10/25/14
to ve...@googlegroups.com
I believe I have tried already every possible constellation here but cannot force it to work. Hmm.

Alexander Lehmann

unread,
Oct 25, 2014, 9:31:15 AM10/25/14
to ve...@googlegroups.com
Could you put up a stripped down version of your project that shows the issue on github or as a gist (or somewhere like dropbox or another file hosting service) so I can take a look?

Not sure what else to try, but maybe I can come up with something ...

Tim Fox

unread,
Oct 25, 2014, 12:55:20 PM10/25/14
to ve...@googlegroups.com
On 24/10/14 22:04, Maciej Żerkowski wrote:
And how to achieve similar with using fat jars?

If you create your project using the Maven archetype, it should include a directory src/main/platform_lib into which you can put any resources that you want to put on the Vert.x classpath (i.e. the same as adding jars in the lib directory of the installation).

There's a README in there that explains this (this one: https://github.com/vert-x/vertx-maven/blob/master/archetype/src/main/resources/archetype-resources/src/main/platform_lib/README.txt )


--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages