Using log4j2 2.19.0 in xml with strict mode, missing attributes - log4j2

I'm trying to migrate from log4j 1.2.13 to log4j2 2.19.0.
I'm using strict mode, but it looks like log4j2 have some problems with strict mode,
this is Log4j-config.xsd file from 2.19.0 : https://github.com/apache/logging-log4j2/tree/rel/2.19.0/log4j-core/src/main/resources it says last update was 5 years ago
and this is Log4j-config.xsd from master branch : https://github.com/apache/logging-log4j2/tree/master/log4j-core/src/main/resources
if you look both of them, it looks like config.xsd from 2.19.0 is not fully complete. But maven says latest version for log4j2 is 2.19.0
My problem is I have lots of appender on my old log4j configuration xml and trying to convert to logj2 configuration, but for example log4j2 appender only have three attributes which are, type, name and filename, and as you know in log4j there is attributes like
<param name="Append" value="true" />
<param name="MaxFileSize" value="500KB" />
<param name="MaxBackupIndex" value="2" />
...
I couldn't find how to give parameter to in log4j2, and there is no description in config.xsd (ver 2.19.0) too. Somehow should I use xsd and dtd's from master branch?
And also for what should my xsi:schemaLocation ?
https://raw.githubusercontent.com/apache/logging-log4j2/log4j-2.19.0/log4j-core/src/main/resources/Log4j-config.xsd
returns 404, I can get xsd for 2.12.x, but later versions there is no xsd on this link.
There is a similar question here: Log4j2 Appender attributes with strict xml config but it asked 9 years before.

Related

Ant-Ivy post-retrieve-trigger

I am trying to tackle some technical debt in our Ant/Ivy system and one of my current tasks is to address some post-retrieve behaviors we currently have. By default, our build system retrieves Ivy dependencies and then extracts compressed artifacts (tar, tar.bz2, gzip, zip only) to a dependency folder, so that our projects have a consistent dependency location:
(project.root)/dependency/.archive <- the compressed dependency location
(project.root)/dependency/extracted-foo` <- the uncompressed dependency
The extraction occurs in a post-retrieve-artifact trigger so that we get the benefit of some of the metadata (paths, names, types, etc., all prefixed with 'dep'.
We currently have one property that can be set to turn off this default behavior for all the dependencies specified in an ivy.xml file. Thus, we are left with an all-or-nothing situation. If we want something in-between, we currently have to use our build.xml file and write some custom code. This is painful because the metadata is not readily available.
I would like to retain the use of the all-or-nothing flag but allow projects to selectively extract items - we have several projects whose build.xml files would be greatly simplified if we could knock the extraction process down to an attribute on the artifact itself.
Thus, my thinking is to use an extra attribute on the artifact tag to "inject" this information and override the ivy.retrieve.pattern to search for this attribute.
Ivy.xml
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
<dependencies>
<dependency org="my.org" name="foo" rev="${foo.version}" conf="${conf.archive}->*" transitive="false">
<artifact name="megapin" type="war" e:expand="expand"/>
</dependency>
</dependencies>
</ivy-module>
Build.xml
This is where I think I'm having trouble getting the expand extra attribute to show up.
Question 1: This does add the "extract" attribute to the artifact name at retrieve time. I can use the contains clause to check if that is there in the dep.to Is there a way to retrieve the extra attributes (e.g., ${dep.extra.expand} ?
<property name="ivy.retrieve.pattern" value="${dependency.dir}/[conf]/[artifact]-[rev])(-[expand]).[ext]"/>
</property>
<target name="ivy-post-retrieve-trigger">
<local name="doexpand"/>
<condition property="doexpand">
<contains string="${dep.to}" substring="expand" casesensitive="false"/>
</condition>
<!-- this step works if the flag is set properly, so I'm leaving out these non-relevant steps-->
<...extract if:isset="doexpand"... />
ivysettings.xml
This file basically has the trigger and other resolver settings.
<triggers>
<ant-call target="ivy-post-retrieve-trigger" prefix="dep" event="post-retrieve-artifact"/>
</triggers>
Question 2: Any suggestions on a "noexpand" name? My concern with the <contains> clause is that the "expand" is going to get hit all the time.
I think I am close to getting this working - but the only information I get is: Property "doexpand" has not been set and thus it is skipping the extraction step. Q3 Any tips/advice/examples on how to use the extra attribute on a trigger with Ant/Ivy?
I ended up adding some additional debugging statements to Ivy (as compiled from source). In the ant-ivy/src/java/org/apache/ivy/ant/AntCallTrigger.java I added the following line:
Message.verbose("\tp.name=" + p.getName() + " | p.value=" + p.getValue() );
If I modified my dependency in my Ivy.xml file to be:
<dependency org="my.org" name="foo" rev="${foo.version}" conf="${conf.archive}->*" transitive="false">
<artifact name="megapin" type="war" e:expand="true"/>
</dependency>
This showed
[ivy:retrieve] p.name=dep.expand | p.value=true
At which point I could do something like
<isset property="dep.expand"/>
or
<istrue value=${dep.expand}/>
This answers my Q1. Additionally, I don't need to add this to the Ivy retrieve pattern (thus changing the filename after retrieve), can use a "true" or "false" value as desired (Q2), and this general guidance answers Q3.

Extended Schedule Task in Sitecore not working

I have created an extended scheduled task with some parameters and has also added Schedule "20160201T235900|20190201T235900|127|00:10:00" to run every 10 minutes.
Frequncy in web.config is also set to 5 minutes. 00:05:00
But It is not at all executing somehow. Can anyone help me out with some possible reasons for this.
Extended Schedule
|||||Task Info
This Extended Schedule template ships with Active Commerce, and is helpful for specifying parameters that are commonly needed when executing Active Commerce tasks, including a site/shop context, database context, and other parameters.
Out of the box however, the Sitecore DatabaseAgent will not execute schedules for items which don't explicitly use Sitecore's Schedule template (even if the template inherits from it, as Extended Schedule does).
To work around this, Active Commerce ships with its own extended DatabaseAgent. You can enable it by enabling the xActiveCommerce.Scheduling.config.example config patch that ships with Active Commerce. In case this example config is missing, I've included its contents below.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<scheduling>
<agent type="Sitecore.Tasks.DatabaseAgent">
<patch:delete />
</agent>
<agent type="Sitecore.Tasks.DatabaseAgent">
<patch:delete />
</agent>
<agent type="ActiveCommerce.Tasks.DatabaseAgent" method="Run" interval="00:10:00" instance="master">
<param desc="database">master</param>
<param desc="schedule root">/sitecore/system/tasks/schedules</param>
<LogActivity>true</LogActivity>
</agent>
<agent type="ActiveCommerce.Tasks.DatabaseAgent" method="Run" interval="00:10:00" instance="core">
<param desc="database">core</param>
<param desc="schedule root">/sitecore/system/tasks/schedules</param>
<LogActivity>true</LogActivity>
</agent>
</scheduling>
</sitecore>
</configuration>
Are you using InitializeSpeedBooster.config? then you have to delete the following lines:
<processor type="Sitecore.Pipelines.Loader.InitializeScheduler, Sitecore.Kernel">
<patch:delete />
</processor>

How to use org.perf4j.log4j.AsyncCoalescingStatisticsAppender in log4j2?

Below is the sample used in log4j 1.x. I am not getting any example to convert the same in log4j2.
<appender name="CoalescingStatisticsAppender"
class="org.perf4j.log4j.AsyncCoalescingStatisticsAppender">
<!--
The TimeSlice option is used to determine the time window for which
all received StopWatch logs are aggregated to create a single
GroupedTimingStatistics log. Here we set it to 10 seconds, overriding
the default of 30000 ms
-->
<param name="TimeSlice" value="30000" />
<appender-ref ref="perf4jFileAppender" />
</appender>
The Appender won't work as is in Log4j 2. It would have to be rewritten.
You may be interested to know that Log4j 2 supports nanoTime timestamps in PatternLayout. This, in combination with the low overhead Async Loggers, allow you to use Log4j as a rough profiling tool.

Java Log4J 2 - Configurate own appender in xml

I tried to configurate Log4J2 per xml-file. I want to register an own appender (which shows an speciale panel if errors happend).
With logback it was no problem - till I wanted to use it in my webStart-Project. So I hope it works with log4j2.
With my own configuration I get an CLASS_NOT_FOUND output.
I am looking the log4j2 xml-shema for:
<appender name="myAppender" class="mypackage.myappender">
I tried everything like
<Appenders>
<Myappender name="MyAppender" class="mypackage.myappender">
</Myappender>
</Appenders>
I hope someone can help me.
P.S.: sorry for my bad english
You would need to implement your appender as a log4j2 plugin.
This is not that difficult (just look at some of the existing appenders to see which annotations to use and methods to implement).
You also need to help log4j2 find your plugin by specifying the appender's package in the configuration:
<Configuration packages="com.mycomp.mylog4j2appenderpackage">
<Appenders>
<MyAppender name="MyAppender" />
</Appenders>
...
</Configuration>

Reload resource bundle in struts2 in Websphere

I have struts.devMode=true in my struts.properties. Which will cause resource bundle to reload each time. But every time when it try to reload it throws exception below. My application is running on websphere 7. Any help will be appriciated.
com.opensymphony.xwork2.util.logging.commons.CommonsLogger error Could not reload resource bundles
java.lang.NoSuchFieldException: cacheList
You can't work with Struts 2 in devMode and Websphere. There isn't many information on the Internet (in French) but what I can understand with my limited French knowledge is that you have to put the server with production settings.
I mean that your struts.xml must be like this to make Struts2 work on Websphere:
<struts>
<constant name="struts.devMode" value="false" />
<constant name="struts.i18n.reload" value="false" />
<constant name="struts.configuration.xml.reload" value="false" />
...
</struts>
The reason that why is this happening is not very clear. The blog explains that maybe is for a different JVM implementation by IBM and maybe it differs in the implementation of the ResourceBundle class that has no private field cacheList and then raises an error when it reloads the i18n labels.
the follow solution worked for me in Tomcat 7 and WebSphere Application Server 7.
LocalizedTextUtil.reset();
ResourceBundle.clearCache(LocalizedTextUtil.class.getClassLoader());
This will clear the ResourceBundle cache.
*devMode and i18n.reload must be false.
Regards,
Felipe

Resources