How do I programmatically disable Hazelcast client's logging? - hazelcast

I used to use networkConfig.setProperty("hazelcast.logging.type", "none") in cluster's network configuration, but I can't see any logging-related configuration methods in any of ClientConfig and ClientNetworkConfig. Please help to save my server's log files.
Hazelcast version: 3.2.5

I think you can do exactly the same thing on the ClientConfig using the ClientConfig.setProperty. Personally I never use it, I prefer to use the commandline option (-Dhazelcast.logging.type=blabla) because this give more predictable logging behavior.

I use Hazelcast with the default JDK logger.
This works for me to save my server's log files:
Logger logger = Logger.getLogger("");
logger.setLevel(Level.WARNING);

Related

Log4j2 NoSQL Cassandra configuration in .properties file

I'm trying to add an appender to Karaf 4.2, to log exceptions to Cassandra (DSE). My "org.ops4j.pax.logging.cfg" file looks like this:
log4j2.rootLogger.appenderRef.cassandrass.ref = Cassandra
# Cassandra Appender
log4j2.appender.cass.type=NoSql
log4j2.appender.cass.name=Cassandra
but it fails with
org.ops4j.pax.logging.pax-logging-api [log4j2] ERROR : NoSQL provider not specified for appender [Cassandra]. Ignored FQCN: org.apache.logging.log4j.spi.AbstractLogger
Null object returned for NoSql in Appenders. Ignored FQCN: org.apache.logging.log4j.spi.AbstractLogger
Unable to locate appender "Cassandra" for logger config "root" Ignored FQCN: org.apache.logging.log4j.spi.AbstractLogger
Almost every configuration example I find is in the xml format. Does anyone have a working example they can share? It is complaining "NoSQL provider not specified" which makes perfect sense. I just don't know how to configure the provider to be Cassandra
This is the guide I'm following: https://logging.apache.org/log4j/2.x/manual/appenders.html#CassandraAppender
It isn't clear in your post what you're trying to achieve. If you're attempting to configure logging for Cassandra, it won't work with Log4j.
Cassandra uses SLF4J with logback so you need to configure it accordingly. For details, see Configuring logging in Cassandra.
If you're using Log4j in your app, have a look at Configuring Log4j with a properties file. Cheers!

Does Hazelcast honor a default cache configuration

In the hazelcast documentation there are a few brief references to a cache named "default" - for instance, here:
http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#jcache-declarative-configuration
Later, there is another mention of cache default configuration here:
http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#icache-configuration
What I would like is to be able to configure "default" settings that are inherited when caches are created. For instance, given the following configuration snippet:
<cache name="default">
<statistics-enabled>true</statistics-enabled>
<management-enabled>true</management-enabled>
<expiry-policy-factory>
<timed-expiry-policy-factory expiry-policy-type="ACCESSED" time-unit="MINUTES" duration-amount="2"/>
</expiry-policy-factory>
</cache>
I'd like for the following test to pass:
#Test
public void defaultCacheSettingsTest() throws Exception {
CacheManager cacheManager = underTest.get();
Cache cache = cacheManager.createCache("foo", new MutableConfiguration<>());
CompleteConfiguration cacheConfig = (CompleteConfiguration) cache.getConfiguration(CompleteConfiguration.class);
assertThat(cacheConfig.isManagementEnabled(), is(true));
assertThat(cacheConfig.isStatisticsEnabled(), is(true));
assertThat(cacheConfig.getExpiryPolicyFactory(),
is(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 2l)))
);
}
Ehcache has a "templating" mechanism and I am hoping that I can get a similar behavior.
Hazelcast supports configuration with wildcards. You can use <cache name="*"> for all Caches to share the same configuration, or apply other patterns to group Cache configurations as you wish.
Note that since you already use Hazelcast declarative configuration to configure your Caches, you should use CacheManager.getCache instead of createCache to obtain the Cache instance: Caches created with CacheManager.createCache(..., Configuration) disregard the declarative configuration since they are configured explicitly with the Configuration passed as argument.

Log4j property in Jetty-9 logging framework

I am switching from jetty-7.6 to jetty-9.2.1. I am facing a issue where jetty server logs are not coming into the log file.
Previously with jetty-7.6:
I was running the server with:
"--ini OPTIONS=Server,jsp,jmx,resources,websocket,ext,plus,annotations" and setting the property : ("log4j.configuration", "/log4j/log4j.properties")
Now with the new version jetty-9.2.1:
I am running the jetty server with module option as:
"--module=server,jsp,deploy,jmx,resources,websocket,ext,plus,annotations" and also setting the same property for log4j : ("log4j.configuration", "/log4j/log4j.properties")
But I am not able to get jetty logs.
Is there anything I am missing or some configuration changes with new version ?
Thanks,
Anuj

Log4j exception lead to application abort

My java application use log4j(flume appender with AsyncAppender) to log to remote log server.
If log server is down, log4j will try to reconnect a few times,but then my java application was shutdown.Is there any possible my java application goes normal with the exception of log4j?
the right solution is :
use AsyncAppender with FlumeAppender. more detail see http://edwardsbean.github.io/blog/2014/01/14/flume-in-action-1/
You have two choices
Catch the exception and ignore it
set the UnsafeMode property to true.

log4j with liferay and tomcat

I have a Liferay setup on the Tomcat6. I used Log4j initially for portlets/webapps by adding log4j.properties file in the classes folder and log4j.jar file in the web-inf/lib.
Now we have few quartz jobs which are available in the tomcat/lib folder and I want to enable log4j logging for these jobs as well.
For these quartz jobs I have copied same log4j.properties file in the tomcat/lib.
With the new configuration I keep getting the following error:
Could not instantiate appender named "JOBS"
A "org.apache.log4j.RollingFileAppender" is not assignable a "org.apache.log4j.Appender" variable.
The class "org.apache.log4j.Appender" was loaded by ...
How to remove this error?
Is there any way I can keep a single log4j.properties file which can be used by both shared/lib as well as portlet/webapps.
According to this post the problem is that you have configured your log4j twice.
My solution would be that you create the logger instance like this
private static Logger logger = Logger.getLogger(FooBar.class.getName());
and not to have log4j.properties under any lib or class folder but having it under a folder named resources.
AFAIK this should be a place where the both parts of your application may have access to.
Known issue in Liferay: http://issues.liferay.com/browse/LPS-9376
In my case, the problem occurred once I started to use ServiceBuilder services, and added Log4J Logger to one of my ...LocalServiceImpl classes.
Once I removed Log4J logging from there everything got back to norm - exception disappeared.
(I made service methods throw exceptions, and was catching them in a code not related to ServiceBuilder read/generated classes, but it could also be done by changing Log4J logger calls to Liferay's LogUtil calls).

Resources