I am trying to change the console output produced by webdrivermanager-java from https://github.com/bonigarcia/webdrivermanager
I have found several tutorials on how to do that but none of them works for me (or I am missing something).
Here is the current console output:
[TestNG-PoolService-2] INFO io.github.bonigarcia.wdm.WebDriverManager - Using chromedriver 91.0.4472.101 (resolved driver for Chrome 91)
[TestNG-PoolService-2] INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as ...
I would like to remove it completely so here are the configurations I tested without success:
On another question here on StackOverflow: How to suppress webdriver-manager logs
The solution is to add logback.xml to the resources folder - tested it and it does not work for me
On the github readme the author is mentioning how to influence logging so i have tested following config:
java.util.logging.Logger.getLogger("org.apache.hc").setLevel(Level.SEVERE);
java.util.logging.Logger.getLogger("org.apache.http").setLevel(Level.SEVERE);
but that does not work either.
I am using webdrivermanager version 4.4.3
Fixed by adding logback to my project as a maven dependancy and a logback.xml file with logging config:
dependancy:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<logger name="org.apache" level="ERROR" />
<logger name="httpclient" level="ERROR" />
</configuration>
Related
I am currently working on a simple web application using javalite webactive and activeJDBC. To start with javalite I simply used https://github.com/javalite/activeweb-simple/ and expanded from there.
One thing which I would like to change, now that I have already implemented a few controllers and models I want to customize the logger:
[qtp1442407170-13] INFO org.javalite.activeweb.RequestDispatcher - {"controller":"app.controllers.HomeController","duration_millis":685,"remote_ip":"0:0:0:0:0:0:0:1","method":"GET","action":"index","url":"http://localhost:8080/home/index","status":200}.
I don't really get what the prefix represents hence I would like to change that part to show date and timestamps.
Following http://javalite.io/logging#log4j-configuration I should be able to customize the logging via log4j.properties in src/main/resources, but this does not seem to make any difference.
The files content:
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %4p %c{1} - %m%n
I suspect that I have somehow overwritten the default logger, although I did not change anything related in the pom.xml or Main.java.
Am I missing something or could it be that the changes somehow get overwritten?
here is a method I have used on all my JavaLite ActiveWeb projects. The requirements are:
I want to log to a console while development - for convenience.
I want to log to a file in any other environment
I want my log file to have a JSON format because I can analyze it in Splunk, ElasticSearch or any other similar tool.
So, I augmented the ActiveWeb with this commit.
Let's do it step by step:
Add a property to the pom file <logger-name>CONSOLE</logger-name>
Add a file log4j.properties with this content:
```
log4j.rootLogger=INFO, ${logger-name}
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d %4p [%t]: %c{1} - %m%n
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=logs/activeweb-simple.log
log4j.appender.FILE.Append=true
log4j.appender.FILE.Encoding=UTF-8
log4j.appender.FILE.layout=org.javalite.logging.JsonLog4jLayout
```
Add an SLF4J dependency to integrate it with Log4J:
```
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
```
Add a profile to the pom:
<profiles>
<profile>
<id>file_log</id>
<properties>
<logger-name>FILE</logger-name>
</properties>
</profile>
</profiles>
Add property filtering to pom:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Lets see how this is working.
When you run the program in a development environment without a profile, maven replaces ${logger-name} in your log4j.properties file for CONSOLE. This way, you use the CONSOLE logger, and everything is printed to your console. If you run your program with profile -Pfile_log, then you Maven will replace ${logger-name} with FILE, so Log4J will log to a corresponding file.
Additionally, see that the console layout is org.apache.log4j.ConsoleAppender, but the file layout is org.javalite.logging.JsonLog4jLayout. The org.javalite.logging.JsonLog4jLayout is a JavaLite integration with Log4J built specifically to integrate with Log4J and produce a JSON output.
So, how do you use it? In a development environment you do not need to do anything special, it just works. When you need to build it, run mvn package -Pfile_log -
I have been reading a lot on this forum,jboss docs and on the internet to successfully get log4j configuration to work with jboss as 7.1.1, I do not want to use the logging subsystem in jboss. I want to use my own log4j configuration. My jboss server is configured in standalone mode. The following is what I did to get log4j configured based on docs :
Define a jboss-deployment-structure.xml as per https://docs.jboss.org/author/display/AS71/How+To#HowTo-HowdoIuselog4j.propertiesorlog4j.xmlinsteadofusingtheloggingsubsystemconfiguration%3F, and I added this in the META-INF directory of my EAR
I added a log4j.xml as is, and packaged inside a jar in the lib directory of my ear.
Removed the logging subsystem and the extension module="org.jboss.as.logging" from standalone.xml.
I did not change the logging.properties that is provided as a startup parameter in the startup.sh as I've read that is the logging that the jboss server will use before the subsystem kicks in.
Inspite of doing all of this I cannot get the application to log as per my log4j configuration.
My reason to use my own log4j configuration instead of the logging subsytem is to be able to use a custom rolling file appender for size-rotating-file-handler, as I want the rotated files to have a timestamp attached to the file name.
Help appreciated,
Ok, so I created a class MyHandler.java that extends from the SizeRotatingFileHandler.java and I override the preWrite method. MyHandler.java is in a package a.b.c. I create a sub directory under modules a/b/c and inside the c directory I add a jar that has just the Myhandler.class file. I add a module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="a.b.c">
<resources>
<resource-root path="RotatingHandler.jar"/>
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="org.jboss.logging"/>
</dependencies>
</module>
Then in the standalone.xml I added an entry for the custom handler
<custom-handler name="FILE3" class="a.b.c.MyHandler" module="a.b.c">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="srveree.log"/>
</custom-handler>
When I start Jboss it says it cant find the class a.b.c.MyHandler. How do I resolve this error ?
UPDATE : I resolved this error. There was a problem in the package structure inside the module. However, I am still going back to the original question of configuring log4j with jboss-as-7.1.1.Final.
I was able to configure log4j with jboss. It turns out that you need to add exculsions seperately for each of the sub-deployments inside your main deployment. For example, I have an ear that has jar and war files budled inside. So I added seperate entries for each of the them in the jboss-deployment-structure.xml and it worked.
<sub-deployment name="your-subdeployment.jar">
<exclusions>
<module name="org.apache.log4j"/>
<module name="org.slf4j" />
<module name="org.apache.commons.logging"/>
<module name="org.log4j"/>
<module name="org.jboss.logging"/>
</exclusions>
</sub-deployment>
One thing you didn't indicate was whether or not you added a log4j library in your EAR/lib folder as well. I assume you probably have though or you should be seeing other errors.
I'm not sure whether or not log4j would have a log4j.xml inside a JAR inside your EAR to be honest. I would think that the EAR/META-INF would be a more appropriate place for your log4j configuration file.
There is no real reason to remove the logging subsystem in this case. Also, I'm not trying to convince you to use it, but you could create a custom handler fairly easily to do what you're looking to do. You could base it on the SizeRotatingFileHandler and then just add a suffix on the rename.
Consider configuration in your standalone.xml at
<subsystem xmlns="urn:jboss:domain:logging:1.1">
Here you can set
<console-handler name="CONSOLE">
<level name="DEBUG"/>
...
<logger category="com.myCompany">
<level name="DEBUG"/>
</logger>
...
Means: your logger in you classes which are in package com.myCompany should log from level DEBUG.
In my web application I reinitialize log4j with my own log4j.xml file.
I already excluded my log4j.jar with following jboss-deployment-structure.xml
<jboss-deployment-structure>
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
After the reinitialization log4j logs everything in stdout
In jboss 5 I used this JVM param
-Dorg.jboss.logging.Log4jService.catchSystemOut=false
With jboss 7 this doesn't work.
How can I configure log4j to not log to stdout?
If there are no special appenders you use, you're probably best using the logging configuration that comes with the application server. It has the advantage of allowing you to make runtime changes from it's management interfaces (web console, CLI, etc.).
You can still use log4j as your logging facade in your application, but you just manage the loggers and handlers (appenders) from the application server.
I had to exclude the following two modules:
<exclusions>
<module name="org.apache.log4j" />
<module name="org.jboss.log4j.logmanager" />
</exclusions>
If I have the following in my services-config.xml file for setting up BlazeDS log file on a linux server, where does it save the log file? Or, does the output show up by default in Flash Builder 4.6 (e.g. no further info in log file)?
I've been trying to figure this out reading
http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?content=services_logging_3.html
but haven't been able to figure it out. I must be missing something obvious. Any advice appreciated.
<logging>
<target class="flex.messaging.log.ConsoleTarget" level="Error">
<properties>
<prefix>[BlazeDS] </prefix>
<includeDate>true</includeDate>
<includeTime>true</includeTime>
<includeLevel>true</includeLevel>
<includeCategory>true</includeCategory>
</properties>
<filters>
<pattern>Endpoint.*</pattern>
<pattern>Service.*</pattern>
<pattern>Configuration</pattern>
</filters>
</target>
</logging>
Is there a way I can specify a location for the log file to be written?
Taken from the link you provided:
Setting the logging target
By default, the server writes log messages to System.out. In the class
attribute of the target element, you can specify
flex.messaging.log.ConsoleTarget (default) to log messages to the
standard output, or the flex.messaging.log.ServletLogTarget to log
messages to the default logging mechanism for servlets for your
application server.
So you either have to configure logging in your application server (for Tomcat: http://tomcat.apache.org/tomcat-7.0-doc/logging.html) or use something like log4j in your servlet.
services-config.xml should then look something like this:
<target class="flex.messaging.log.ServletLogTarget" level="warn">
<properties>
<prefix>[BlazeDS] </prefix>
<includeDate>true</includeDate>
<includeTime>true</includeTime>
<includeLevel>true</includeLevel>
<includeCategory>true</includeCategory>
</properties>
<filters>
<pattern>Endpoint.*</pattern>
<pattern>Service.*</pattern>
<pattern>Message.*</pattern>
<pattern>DataService.*</pattern>
<pattern>Configuration</pattern>
</filters>
</target>
</logging>
Sidenote: We use log4j and spring-flex, which provides org.springframework.flex.core.CommonsLoggingTarget to handle BlazeDS output.
services-config.xml
<logging>
<target class="org.springframework.flex.core.CommonsLoggingTarget" level="debug">
<properties>
<categoryPrefix>blazeds</categoryPrefix>
</properties>
</target>
</logging>
log4j.properties
log4j.appender.myAppLog=org.apache.log4j.RollingFileAppender
log4j.appender.myAppLog.File=${catalina.base}/logs/myAppLog.txt
log4j.appender.myBlazeLog=org.apache.log4j.RollingFileAppender
log4j.appender.myBlazeLog.File=${catalina.base}/logs/myBlazeLog.txt
log4j.rootLogger=DEBUG,myAppLog
log4j.logger.blazeds=ALL,myBlazeLog
How can I use log4j with JBoss 7.1?
I have a log4j-1.2.16.jar in my WebContent/WEB-INF/lib folder. When I output the result of Logger.getRootLogger().getClass().toString() I get class org.jboss.logmanager.log4j.BridgeLogger which is wrong.
If I add Dependencies: org.apache.commons.logging to my MANIFEST.MF file I get the same result.
This results into the problem that my log4j.properties file (which I created unter WEB-INF/classes) is ignored.
There will soon be a way that will just work for you, but currently you have to exclude the log4j dependency from your deployment. You will also have to manually invoke the PropertyConfigurator.configure() to load the properties file.
The following file (jboss-deployment-structure.xml) needs to contain the following:
<jboss-deployment-structure>
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
Then adding including your own version of log4j in the WEB-INF/lib directory should work as you expect it to.