I have a requirement to maintain separate logging files EAR1.log and EAR2.log for 2 Java EE applications EAR1 and EAR2 respectively using LOG4J2 v2.1. Going through the internet, I could see help specific to LOG4J v1.x, but couldn’t find any for LOG4J2.
EAR1 (need to use “EAR1-log4j2.xml”):
1. Web project “web1”
2. EJB project “ejb1”
3. Java project “java1”
4. Java project “java2”
5. Java project “java3”
EAR2 (need to use “EAR2-log4j2.xml”):
1. Web project “web2”
2. EJB project “ejb2”
3. Java project “java1” (same as above)
4. Java project “java2” (same as above)
5. Java project “java3” (same as above)
http://logging.apache.org/log4j/2.x/manual/migration.html
http://logging.apache.org/log4j/2.x/manual/logsep.html
what is working now:
my log4j2.xml is placed in ApplicationServer classpath & a single log is successfully getting written for both the EAR’s
my completed attempts to maintain separate log files for both EAR’s:
• Modifying web.xml only applies the logging change to the web project alone
• I tried the following code, but this applies only to current class
LoggerContext loggerCtx = Configurator.initialize("mrpst", null, PathOfMyLog4j2XmlPath );
Logger log = loggerCtx.getLogger("MyClassName");
I’m trying to check if it is possible to complete this requirement by editing log4j2.xml alone(without code change). Appreciate if a documentation link can be provided or any alternate approach.
My suggestion is to inject context into your log event and filter on that context using a logger route, which directs to an appropriate appender.
At the point of logging:
String routeKey = SOME_FIELD_THAT_IDENTIFIES_CONTAINER;
ThreadContext.put( "myEARroute", routeKey );
In your log4j2.xml config:
<Routing name="myEARroute">
<Routes pattern="$${ctx:myEARroute}">
<!-- if you forget to inject context, the routing key will be empty -->
<Route
key="$${ctx:myEARroute}"
ref="STDOUT" />
<Route
key="EAR1"
ref="myEAR1Appender" />
<Route
key="EAR2"
ref="myEAR2Appender" />
</Routes>
</Routing>
Now you just have to create appenders matching your appender names:
<RollingRandomAccessFile
name="myEAR1Appender"
filename="logs/Ear1.log"
<!-- fill in the rest of your appender config, as desired -->
</RollingRandomAccessFile>
repeat for other appenders.
Related
I'm trying to localize a SSRS reports. I have a DLL that uses a ResourceManager to access resource files that are embedded in the dll. My report has a reference to the dll. The dll is signed and strongly named. The dll and resource files' dll are compiled and in MicrosoftVisualStudio9.0/Common7/IDE/PrivateAssemblies and in Microsoft SQL Server\MSRS10.REPORTSERVER\Reporting Services\ReportServer\bin. The resource dll's are also installed in the GAC using gacutil.
Occasionally the SSRS correctly finds the resource key it needs and displays it. However, when changing the resource files to add more key's and values, I cannot get the SSRS to access the newly added files. I have repeated all of the above steps and even uninstalled and installed the resources in the GAC. Still I cannot get it to work.
Any idea what step I'm missing? Clearly the process works, I'm just not repeating something that I need to be.
For those interested in a slightly different approach, you may want to try using a localization assembly that doesn't use the standard resource management, but instead relies on simple file IO. This makes making changes to existing resx files or adding new ones less problematic. You can add or change the resx files and instantly be able to retrieve values for use in the reports. I followed this example, with only minor tweaks and have been very happy with the results:
http://www.codeproject.com/Articles/294636/Localizing-SQL-Server-Reporting-Services-Reports
One note though, the steps to follow when adding the new CodeGroup are lacking a bit in that if you place the new CodeGroup anywhere except after the unnamed UnionCodeGroup (it's the one with the Url="$CodeGen$/*") your attempts to access your custom assembly will fail.
After a lot of digging I was able to find confirmation of this on one of the msdn pages (see the "Placement of CodeGroup Elements for Extensions" section). Their wording was that "it is recommended", but from my testing I'd say it's required, at least when testing directly on the report server:
http://msdn.microsoft.com/en-us/library/ms152828.aspx
The xpath to use in wix for this location in the rssrvpolicy.config file is:
//PolicyLevel/CodeGroup/CodeGroup[\[]#class='FirstMatchCodeGroup'[\]]/CodeGroup[\[]#PermissionSetName='ReportLocalization'[\]]
Here's an example of how this can be done in WiX using the util:XmlConfig extension:
<DirectoryRef Id="TARGETDIR">
<Component Id="I18N_RSSRVPOLICY_CONFIG" Guid="some GUID">
<util:XmlConfig
Id="RS_i18n_PermissionSet_remove_if_already_exists"
File="[SQLREPORTINGSERVICESPATH]ReportServer\rssrvpolicy.config"
Action="delete"
On="install"
ElementPath="//NamedPermissionSets"
VerifyPath="//NamedPermissionSets/PermissionSet[\[]#Name='ReportLocalization'[\]]"
Node="element"
Sequence="100">
</util:XmlConfig>
<util:XmlConfig
Id="RS_i18n_PermissionSet_add"
File="[SQLREPORTINGSERVICESPATH]ReportServer\rssrvpolicy.config"
Action="create"
On="install"
ElementPath="//NamedPermissionSets"
VerifyPath="//NamedPermissionSets/PermissionSet[\[]#Name='ReportLocalization'[\]]"
Node="document"
Sequence="101">
<![CDATA[
<PermissionSet class="NamedPermissionSet" version="1" Unrestricted="true" Name="ReportLocalization" Description="A special permission set that allows Execution and Assertion" />
]]>
</util:XmlConfig>
<util:XmlConfig
Id="RS_i18n_CodeGroup_remove_if_already_exists"
File="[SQLREPORTINGSERVICESPATH]ReportServer\rssrvpolicy.config"
Action="delete"
On="install"
ElementPath="//PolicyLevel/CodeGroup/CodeGroup[\[]#class='FirstMatchCodeGroup'[\]]"
VerifyPath="//PolicyLevel/CodeGroup/CodeGroup[\[]#class='FirstMatchCodeGroup'[\]]/CodeGroup[\[]#PermissionSetName='ReportLocalization'[\]]"
Node="element"
Sequence="102">
</util:XmlConfig>
<util:XmlConfig
Id="RS_i18n_CodeGroup_add"
File="[SQLREPORTINGSERVICESPATH]ReportServer\rssrvpolicy.config"
Action="create"
On="install"
ElementPath="//PolicyLevel/CodeGroup/CodeGroup[\[]#class='FirstMatchCodeGroup'[\]]"
VerifyPath="//PolicyLevel/CodeGroup/CodeGroup[\[]#class='FirstMatchCodeGroup'[\]]/CodeGroup[\[]#PermissionSetName='ReportLocalization'[\]]"
Node="document"
Sequence="103">
<![CDATA[
<CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="ReportLocalization" Name="Verint.SSRS.Localization" Description="This grants the Verint.SSRS.Localization.dll ReportLocalization Permissions">
<IMembershipCondition class="UrlMembershipCondition" version="1" Url="UPDATE_ME"/>
</CodeGroup>]]>
</util:XmlConfig>
<util:XmlConfig
Id="RS_i18n_CodeGroup_update"
File="[SQLREPORTINGSERVICESPATH]ReportServer\rssrvpolicy.config"
Action="create"
On="install"
ElementPath="//IMembershipCondition[\[]#Url='UPDATE_ME'[\]]"
Name="Url"
Value="[SQLREPORTINGSERVICESPATH]ReportServer\bin\Verint.SSRS.Localization.dll"
Node="value"
Sequence="104">
</util:XmlConfig>
<util:XmlConfig
Id="RS_i18n_REDP_CodeGroup_update"
File="[SQLREPORTINGSERVICESPATH]ReportServer\rssrvpolicy.config"
Action="create"
On="install"
ElementPath="//CodeGroup[\[]#Name='Report_Expressions_Default_Permissions'[\]]"
Name="PermissionSetName"
Value="FullTrust"
Node="value"
Sequence="105">
</util:XmlConfig>
</Component>
</DirectoryRef>
I recommend backing up the original config files (with WiX or custom actions). This can make uninstall easier since you can just replace those originals, and also because you can test this over and over again till it's doing what you want. Good luck to you all!
Are your rebuilding and redeploying all the satellite assemblies with each of your updates (including in the GAC)?
If not, it sounds like the problem is due to assembly versioning. There is a SatelliteContractVersion attribute that you can apply to your main assembly to help with this problem. Although rebuilding/resigning/redeploying all satellite assemblies each time you deploy an update may be easier.
I don't want to include or make application.xml in ear tag
How can i off this parameter
<ear earfile="${builddir}/myapp.ear"
appxml="ear_deploy_descriptor/application.xml"
basedir="${builddir}"
includes="*.jar,*.war"/>
Please see earTask documentation at http://ant.apache.org/manual/Tasks/ear.html.
If you specify update="true" then the appxml attribute is not required.
A Java EE 5 application is not required to provide an application.xml file in the EAR file.
There seems to an issue with ANT when dealing with this. This was reported here: https://issues.apache.org/bugzilla/show_bug.cgi?id=51761
Try using the jar task instead of the ear and it should work.
<jar destfile="${builddir}/myapp.ear"
basedir="${builddir}"
includes="*.jar,*.war"/>
When using JBOSS Tools, M2E and M2E-WTP creating a new composite component wants to put the newly created component in the wrong directory. It also looks for components in the wrong directory.
It should be putting it in the directory:
src/main/webapp/resources/components/group-name/tagname.xhtml
but instead it is looking for it (and a quick fix creates file) in:
target/m2e-wtp/web-resources/resources/components/group-name/tagname.xhtml
Here are the versions I am using:
JBoss Tools RichFaces for Eclipse Version:
3.2.1.v20110730-1214-H169-Final
M2E - Maven Integration for Eclipse
Version: 1.0.0.20110607-2117
Maven Integration for WTP
Version: 0.13.1.20110728-1800
Update:
Seems to pick the first path in .settings/org.eclipse.wst.common.component file. Changing the non m2e to be first seems to make it want to put it in the right place.
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="hcbb">
<wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="hcbb"/>
<property name="java-output-path" value="/hcbb/target/classes"/>
</wb-module>
</project-modules>
However, it is still complaining about missing or invalid attributes and not doing auto completion on the custom components.. Not sure if JSF Tools even does that though.
I believe this issue is fixed in later release of joss tools 3.3.x.
If not please open bug and we'll look at it.
I have been trying to find an answer to my question and could not find it; hence I will put the solution here. I hope it is helpful to others.
Problem:
I want my Wix project to build in TFS 2010 build process. As part of this, I want the source files location for my Wix to point to the build location of the TFS. For example, I want:
<File Id="ABC" KeyPath="yes" source="C:\Builds\1\MyBuild\assembly.dll" />
to be:
<File Id="ABC" KeyPath="yes" source="$(var.TFSLOCATION)\assembly.dll" />
The 'TFSLOCATION' is a wix property that needs to be populated with the location of TFS build. This needs to happen during the build process, where the build location path is passed to the Wix project.
Solution:
I read the following article:
http://www.ageektrapped.com/blog/setting-properties-for-wix-in-msbuild/
So this is what I did to my Wix project file (wixproj):
In order to set wix property from TFS MSBuild process the wix project file needs two changes:
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<ProductVersion>3.5</ProductVersion>
<SourceLocation Condition="'$(SourceLocation)' == '' ">UNKNOWN</SourceLocation>
<ProjectGuid>{cae7e273-2de5-4a60-9c4f-9da5f094caf5}</ProjectGuid>
<SchemaVersion>2.0</SchemaVersion>
<OutputName>N4S.MSO.BAM.Installer</OutputName>
<OutputType>Package</OutputType>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>LOCATION=$(SourceLocation)</DefineConstants>
</PropertyGroup>
In the above xml, please note the following two lines:
<SourceLocation Condition="'$(SourceLocation)' == '' ">UNKNOWN</SourceLocation>
<DefineConstants>LOCATION=$(SourceLocation)</DefineConstants>
The first line specifies a property 'SourceLocation' and sets it to a default 'UNKNOWN' value, if is is not set. The second line defines a constant called 'LOCATION' in the 'Release' configuration. The value of this constant is set to the value of 'SourceLocation' property.
Now, you need to make the following changes to your Product.wxs file (or whatever the name of your wxs file is).
Define a wix property first.
<?define TFSLOCATION="$(var.LOCATION)"?>
Now, update the File elements.
<File Id="ABC" KeyPath="yes" source="$(var.TFSLOCATION)\assembly.dll" />
TFS 2010 build template change
Open the TFS 2010 build template.
Look for a task 'Run MSBuild for Project'.
Open the properties for this task and go to 'CommandLineArguments' property.
Set the value for this property to:
String.Format("/p:SourceLocation={0}", BinariesDirectory)
Done
You now have a wix property populated from your TFS build process.
If you set a reference in your wixproj file to the project(s) you are building you can reference their target paths. So if you have two projects MyProject and MyProjectInstaller, set a reference in MyProjectInstaller to MyProject.
Now in the product.wxs file your File elements would look like this:
<File Id='EXE' Name='$(var.MyProject.TargetDir)\MyProject.exe' />
<File Id='DLL' Name='$(var.MyProject.TargetDir)\MyProject.dll' />
...
The benefit to this is that the target dir is correct regardless of whether you're building locally or on a build server.
Answering the question so it doesn't show up with no answers even though the answer is in the question.
I ended up using the same approach, but with a few important improvements.
1) I passed both the SourcesDirectory and the BinariesDirectory from TFS build process template to MSBuild as separate properties, so that I have access to both of them.
2) So that the resulting MSBuild properties are available to every task executed in the MSBuild project, I added them to $(CustomPropertiesForBuild) in the BeforeBuild target.
3) Rrather than adding the DefineContants element to the PropertyGroup, I added a CreateProperty to the BeforeBuild target.
2 and 3 were done for the following reason having to do with running multiple Wix project solutions in a single TFS build. If you define the constant as originally suggested, two things can happen.
First, if you run heat.exe in your WiX project as part of a build that has multiple WiX projects, an issue can occur where the DevEnv holds onto the process handles and the constant is not redefined on each run unless you clean the Output folder and release the file handle.
Second, if for any reason one of your Wix projects does not get built (the configuration does not specify to build it or the specified configuration is invalid for the project) then for some reason, the MSBuild property gets reset to null and thus the constant is redefined as null, so you lose the property. If on the other hand, you define the property by overriding the BeforeBuild target, everything works properly.
Note that you have to override the BeforeBuild property, not the BeforeEndToEndIteration property, for this to work correctly.
I'm using NLog to log to file. Is there a way to configure it to create a new log file when the current one reaches a certain threshold (eg ~50mb)? Can it be done from the configuration file or code?
Yes:
fileName="${basedir}/logs/logfile.txt"
archiveFileName="${basedir}/archives/log.{#####}.txt"
archiveAboveSize="5242880"
archiveNumbering="Sequence"
concurrentWrites="true" <!-- http://nlog-project.org/doc/2.0/sl2/html/P_NLog_Targets_FileTarget_ArchiveAboveSize.htm -->