trying to convert rcp Application into log4j2 but ibatise and DB logs are not getting into log file - eclipse-rcp

Added this in log4j2.xml but queries are not getting printed to log file
<AsyncLogger name="com.ibatis" level="INFO" additivity="false">
<AppenderRef ref="FILE" />
</AsyncLogger>

Related

How to 'censor' some data in libraries self-generated logs?

I am using the library scalikejdbc for my Application. And when i read the logs, that scalikejdbc generates itself, it gives me something like that:
06:02:16.891 [main] DEBUG scalikejdbc.ConnectionPool$ - Registered connection pool : ConnectionPool(url:jdbc:sqlserver://foo.bar:8080;databaseName=foobar;user=user;password=**PASSWORD**;...
So scalike itself throws my database user's password into the logs, which is inappropriate.
I was thinking about filtering those logs at all with something like https://logback.qos.ch/manual/filters.html , but I do need the odd information from those logs from scalike, so I cannot filter them fully.
What do I have now:
06:02:16.891 [main] DEBUG scalikejdbc.ConnectionPool$ - Registered connection pool : ConnectionPool(url:jdbc:sqlserver://foo.bar:8080;databaseName=foobar;user=user;password=somepassword;
What am I try to get:
06:02:16.891 [main] DEBUG scalikejdbc.ConnectionPool$ - Registered connection pool : ConnectionPool(url:jdbc:sqlserver://foo.bar:8080;databaseName=foobar;user=user;password=CENSORED;
Consider using replace conversion word in logback.xml configuration, for example,
%replace(%msg){"password=.*", "password=CENSORED"}
which given
logger.debug("password=123456")
should output something like
[debug] application - password=CENSORED
Docs state
replace(p){r, t} Replaces occurrences of 'r', a regex, with its
replacement 't' in the string produces by the sub-pattern 'p'. For
example, "%replace(%msg){'\s', ''}" will remove all spaces contained
in the event message.
Here is an example of my logback.xml:
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %replace(%msg){"password=.*", "password=CENSORED"}%n %xException{10}</pattern>
</encoder>
</appender>
<logger name="play" level="INFO" />
<logger name="application" level="DEBUG" />
<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />
<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
</configuration>

Kubernetes log location inside the pod

I have a docker image for a Spring Boot app with the log file location as --logging.config=/conf/logs/logback.xml and the log file is as follows.
I am able to get the logs as
kubectl log POD_NAME
But, unable to find the log file when I log in to the pod. Is there any default location where the log file is placed as I haven't mentioned the logging location in the logback.xml file.
Logback file:
<?xml version="1.0" ?>
<configuration>
<property name="server.encoder.pattern"
value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %-5level : loggerName="%logger{36}" threadName="%thread" txnId="%X{txnId}" %msg%n" />
<property name="metrics.encoder.pattern"
value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %-5level : %msg%n" />
<!-- Enable LevelChangePropagator for jul-to-slf4j optimization -->
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator" />
<appender name="METRICS" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${metrics.encoder.pattern}</pattern>
</encoder>
</appender>
<logger name="appengAluminumMetricsLogger" additivity="false">
<appender-ref ref="METRICS" />
</logger>
<appender name="SERVER" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${server.encoder.pattern}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="SERVER" />
</root>
</configuration>
What you see from kubectl logs is console log from your service. Only console log can be seen like that and this is via docker logs support.

JBoss EAP 6.2 and Log4j2 stops writing logs after some time

I am using Log4j2 (RollingFile with routes) in my web application to log application specific logs in a few separate log files. The log4j2.xml file is bundled with in the WAR file.
Log files are generated and logs are generating fine to start with. After some time, it stops writing logs to the existing file and fails creating new folders/files too.
On restart everything resumes working and that is for some time only.
Tried monitoring, couldn't figure out any specific pattern or steps to simulate it.
<Configuration status="error" name="logger">
<Properties>
<Property name="logpath">path_to_log_file</Property>
</Properties>
<Appenders>
<Routing name="RoutingUserLogFile">
<Routes pattern="$${ctx:user}/">
<Route>
<RollingFile name="UserLogFile" fileName="${logpath}/${ctx:user}/MyLogFile.log" filePattern="${logpath}/${ctx:user}/%d{dd-MM-yyyy}-MyLogFile-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %-40C{1.} %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
<SizeBasedTriggeringPolicy size="4 MB" />
</Policies>
</RollingFile>
</Route>
</Routes>
</Routing>
</Appenders>
<Loggers>
<Root>
<level value="debug" />
<AppenderRef ref="RoutingUserLogFile" level="debug" />
</Root>
</Loggers>
</Configuration>

Is there a way to log queries on Neo4J like Hibernate?

So, here is the scenario:
I have Neo4J server running locally with some data in it
I have a web app using spring-data-neo4j
The following code is based on the example code Cineasts:
public interface CrewRepository extends GraphRepository<Crew> {
Iterable<Crew> findByNameLike(String name);
#Query("start thinker=node({0}) match thinker-[:crews]-crews return crews")
Set<Crew> findByThinker(Long thinkerId);
}
No news here. The problem is: the query findByNameLike doesn't work whereas the findByThinker does.
I have modified my log configuration file many times - final version is the one below - but, doesn't matter what I try, I can't see any queries being logged - either on my log file or on the server.
<logger name="org.neo4j">
<level value="DEBUG" />
<appender-ref ref="console" />
</logger>
<logger name="org.springframework.data.neo4j">
<level value="DEBUG" />
<appender-ref ref="console" />
</logger>
<root>
<priority value="error" />
<appender-ref ref="console" />
</root>
All I want is the log the queries so I can see if it's a bug on spring-data-neo4j or if I'm missing something... I have looked through the documentation of both, code examples and couldn't find anything that specific.
Any help? Thank you!
You can enable query logging by adding the following lines to your log4j.xml:
<logger name="org.springframework.data.neo4j.support.query">
<level value="debug" />
</logger>
If anyone lands here looking for how to log queries when Neo4j Server is accessed remotely over the REST API, use
<logger name="org.springframework.data.neo4j.rest.SpringRestCypherQueryEngine">
<level value="debug" />
</logger>
If you're using Spring Data Neo4j and want to see the derived queries corresponding to your DAO methods,
<logger name="org.springframework.data.neo4j.repository.query.DerivedCypherRepositoryQuery">
<level value="debug" />
</logger>

log4net error in NUnit: "Attempted to append to closed appender named []."

When I run some integration tests via NUnit, everything works, including logging. When I run any test a second time, no exception is thrown, but logging ceases to work. Instead, log4net writes this to the console:
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
Here is the log4net configuration:
<log4net debug="true" >
<appender name="console"
type="log4net.Appender.ConsoleAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<priority value="DEBUG" />
<appender-ref ref="console" />
</root>
<logger name="NHibernate">
<level value="WARN" />
</logger>
<logger name="NHibernate.SQL" >
<level value="DEBUG" />
</logger>
</log4net>
The setup code is in a static constructor in the SUT:
log4net.Config.XmlConfigurator.Configure();
I managed to get the same error with a variety of other appender settings. What causes this error? I want to know what the cause is so I know how to fix it, and also how to reproduce this in a production scenario (if that is possible) so I can keep it from happening to production code.
I am using NHibernate 2.0.1.GA and the log4net version that comes with it (1.2.10.0).
Well if you look at the error it says [TextWriterAppender] this means log4net is trying to to append the log message to a TextWriter whereas the config which you gave doesn't have any.
Either there is another config file with a log4net tag being loaded or in code you are anywhere calling up LogManager.Shutdown()