log4j2 enabling debug for specific classes from environment variable - jboss

we are deploying a Java web application in JBoss 7.. 3 EAP.
We need to enable set the debug level for some specific classes (i.e. org.mycompany.mypackage).
As described here:
https://logging.apache.org/log4j/2.x/manual/configuration.html
just setting the environment variable
LOG4J_DEBUG
the log level is set to debug for whole system.
We wonder if there is a way to do it for specific classes/packages
Thank in advance
r.

The LOG4J_DEBUG environment variable does not enable debug logging for your application. It enables debug logging for the internals of Log4j 2. You set the default logging level for your applicaton by specifying a level on the Root Logger.
<Loggers>
<Root leve="info">
<Appender-Ref ref="Console"/>
</Root>
</Loggers>
You could change this so that the default level can be set from an environment variable by doing:
<Loggers>
<Root leve="${env:DEFAULT_LEVEL:-INFO}">
<Appender-Ref ref="Console"/>
</Root>
</Loggers>
The way to set the logging level for specific classes or Packages is to use a log4j configuration file as described in that same section. If you want the levels to be configured via environment variables then you can do that by doing something like:
<Logger name="com.mycorp.myservice.dao" level="${env:DAO_LEVEL:-WARN}"\>
This will use a default value of WARN if the environment variable named DAO_LEVEL is not present.

Related

Enable logging in Scalardb

How do I enable logging in Scalardb? Does it support logback? The ScalarDB logic in my application is throwing NullPointerException. I want to enable traces to understand where the problem might be.
Scalar DB uses slfj4 so various logging frameworks such as logback and log4j can be used.
https://github.com/scalar-labs/scalardb/blob/master/build.gradle
You need to build your application with such logging frameworks and configure
them properly.
For more information regarding slf4j, please refer to slf4j site.
This seem to work - <logger name="com.scalar" level="DEBUG" additivity="true"> <appender-ref ref="STDOUT"/> </logger>

Continue the Wix setup after having a service that could not start

We have a setup in which we have a service that we try to install and run.
For some reason, the service cannot start(due to a port already in use). This isn't critical for us and should not stop the setup.
The service is declared like this:
<DirectoryRef Id="BIN">
<Component Id="MyService" Guid="*" SharedDllRefCount="yes">
<File Id="MyService.exe" Name="MyService.exe" KeyPath="yes" Vital="no" Compressed="default" DiskId="1" Source="$(var.DirDotfuscated)\MyService.exe" />
<ServiceControl Id="Install" Name="MyService" Start="install" Stop="install" />
<ServiceControl Id="Uninstall" Name="MyService" Stop="uninstall" Remove="uninstall" />
<ServiceInstall Id="NewServiceInstall2" Name="MyService" DisplayName="My Service" Type="ownProcess" Interactive="no" Start="auto" ErrorControl="normal" Description="My service" Vital="no" />
</Component>
<Component Id="Xms_HostService_Files" Guid="*" SharedDllRefCount="yes">
<File Id="MyService.exe.config" Name="MyService.exe.config" Vital="no" Compressed="default" DiskId="1" Source="$(var.DirDotfuscated)\MyService.exe.config" />
<File Id="MyServiceCommon.dll" Name="MyServiceCommon.dll" Vital="no" Compressed="default" DiskId="1" Source="$(var.DirDotfuscated)\MyServiceCommon.dll" />
<File KeyPath="yes" Id="MyServiceCore.dll" Name="MyServiceCore.dll" Vital="no" Compressed="default" DiskId="1" Source="$(var.DirDotfuscated)\MyServiceCore.dll" />
</Component>
</DirectoryRef>
When we execute the setup, we get this error:
And then, we only have the option to Retry(which will also fail) or cancel(that stops the setup).
We tried so many things(only put serviceInstall, not serviceControl, ...) but at some point we always have an error.
How should we manage this?
Attempted Answer (without ability to test):
What happens if you set the ServiceControl element's Wait attribute to "no"? I don't have a service exe to test with at the moment, but I believe that could work as you intend it.
Custom actions should generally be avoided for reliability reasons, but on the other hand - if you do need something special - that's what they are there for. Be prepared for most deployment problems to originate from your custom actions though: Why is it a good idea to limit the use of custom actions in my WiX / MSI setups?
Some further advice (which was not asked for :-) ):
You should not install multiple binaries with one component. You should use one file per component for many reasons. Windows Installer best practice specifically dictates to have only one binary per component, but in my opinion you should use one component per file in general to make minor upgrades and patching possible, and self-repair more reliable.
To better understand component reference counting: Change my component GUID in wix?
By eliminating hard-coded GUIDs you can take advantage of WiX's advanced auto-GUID creation concept. This will change the component GUID if the absolute installation path changes. This is correct behavior for component reference counting. Auto-magic. You either set Guid="*" or just leave out the Guid attribute entirely. A few installation locations need a hard coded GUID - the WiX compiler will warn you and explain why.
If you do change the component structure (to use one file per component) you should change the installation path to "break the link to past sins" with regards to component reference counting. This is a very complex topic to explain, but changing the installation path will sort all problems for you - if you also enable the auto component GUIDs I mentioned in the previous point. Keep the path stable from then on (until you have a major new version).
You can do it as simple as adding a sub folder with the the application's major (and minor?) version to the main installation folder hierarchy: "Program Files\MyCompany\MySoftware\5" instead of "Program Files\MyCompany\MySoftware".
I would only add the major version to the path and keep the installation path stable throughout your application's lifetime and then increment when you want to break the link to previous installers for a major new software version (for example if you want to install two versions side-by-side - your application must be built to handle this properly, i.e not overwriting shared settings in the registry from both versions etc...).
You might want to consider simplifying your WiX source file by only specifying values for attributes that are non-standard (otherwise rely on defaults). This can substantially simplify your WiX source files. Here is an example: Syntax for guids in WIX?
Just a quick sample inline (same as in link above - check it out), this is all that is required to install a normal file with default attributes / parameters - all other attributes default well - unless you want to override something:
<Component>
<File Source="..\File.dll" />
</Component>
Some links:
Windows Installer Best Practices (full list).
Windows Installer Best Practices - Organizing Applications into Components (specifically for component creation).
When component reference counting has gone haywire (missing files after upgrades, unexpected removal of shared files on uninstall, etc...): WiX 3.8: Two MSI using the same registry values. How to delete registry values only if both MSI are uninstalled?
Drop the ServiceControl element in lieu of a CustomAction element with #DllEntry="WixQuietExec" set, then use a standard means of starting the service like net start foo and ignore the result. See Quiet Execution Custom Action for details.

Is there Any Way to Enforce RuntimeUnenhancedClasses in EE Configuration

I just spent a half hour debugging some new code that's not broken because I forgot to check (again!) my logs for this dreaded message:
WARN openjpa.Enhance - Creating subclass for ...
I'm running OpenJPA 2.1.0 inside an OpenEJB 3.2 snapshot build, Java 1.6.0_25, and Eclipse Helios. My entities are enhanced using the ant PCEnhancerTask.
My META-INF/openjpa.xml contains
<property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" />
<property name="openjpa.DynamicEnhancementAgent" value="false" />
Is there anyway with this EE configuration to have OpenJPA enforce the RuntimeUnenhancedClasses option as it does in an SE configuration?
I suspect my 'real' problem stems from an Eclipse svn update that sometimes touches my JPA entity source, causing a build that overwrites my enhanced classes.
It's frustrating how often I run a unit test from the IDE that fails in some weird way, and I go digging through my code looking for a problem when all I need to do is run the enhancer.
Put the <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" /> META-INF/persistence.xml.
Looks like we're logging this action on debug level (maybe it should be info level), but OpenEJB will set that property to the default as it was in OpenJPA 1.x so that apps that worked with OpenEJB 3.1.x/OpenJPA 1.x will still work without modification in 3.2.x. If the property is already set in the persistence.xml it will never be overridden, so setting it there will have the effect you want.
Open to suggestions on how to save others in the same boat some time in the future. Seems either looking in the openjpa.xml file and seeing the property set already or issuing the log message on info would do it -- or both.
It sounds like for whatever reason your properties aren't being picked up when running in the container.
I have a number of possible solutions:
Try setting your properties in META-INF/persistence.xml. I assume you have these properties in the openjpa.xml file for a reason, but it might help us figure out where the real problem is.
Set -Dopenjpa.RuntimeUnenhancedClasses=false as a JVM property. This will apply to all PUs for a given JVM.
Move to a version of OpenJPA that is >= 2.0.0. RuntimeUnenhancedClasses was turned off as the default behavior in that release.

how to run application of spring batch using CommandLineJobRunner

I am creating an application using spring batch in which i am reading data from database and populate it in a file placed in D drive. My application does not have any errors but when i run my app, the console does not show any exceptions. In fact, the console is blank completely. I am not able to figure out if the app is actually getting executed or not.
I am using CommandLineJobRunner class for executing my job.
All your comments would be of great help.
Thanks
Reading data from database and populate it in a file placed in D drive
I am not able to figure out if the app is actually getting executed or not
Did you check the D drive? Is the file there? Was it populated as expected?
As a rule of thumb => write a test, that would make sure the file is there on the D drive, and that it has all the data expected. But as a start, you can just check it manually.
As to your question => The reason that you do not see anything, is most likely related to the logging misconfiguration.
If you use log4j / slf4j / etc, make sure to place a default (for a start) lo4j.properties / lo4j.xml file in your class path [e.g. root of your project]. If you use logback, make sure a logback.xml is in your classpath with (for a start) default configuration:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
<logger name="org.root.level.package" level="debug"/>
<root level="info">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
Did you develop your application using an IDE like Eclipse? If so, you might try debugging your code so that you can find out the reason why your application is not working as you expected it to be.

Environment variable expansion in persistence.xml (JPA)

I am developing a Eclipse RCP plugin which uses JPA.
I tried to specify the database path via a variable give to the JVM on runtime.
The property is set correctly but the database is created in a folder named after the variable name (here: ${DBHOME}).
<property name="javax.persistence.jdbc.url" value="jdbc:derby:${DBHOME};create=true"/>
Is there a possibility to fix this?
Thx
That should work but only for JVM variables, not OS/Shell environment variables. To make your example work, you need to start the JVM with -DDBHOME=your/path.
To make this work with shell variables, you need to add -DDBHOME=$DBHOME (*nix) or -DDBHOME=%DBHOME% (win) to the JVM launch command line.