Log4j 2 rollover not happening at expected time - log4j2

I am using log4j2 Rolling File appender for logging. The traffic for the logger is quite sparse. I want the logger to rollover the file at the appropriate time. How can i do that ?
This is the output of ls -lrth command on the log files.
-rw-r--r-- 1 root root 136 Apr 27 15:51 logfile-04-20150427-07-00.log.gz
-rw-r--r-- 1 root root 133 Apr 27 23:18 logfile-04-20150427-15-00.log.gz
-rw-r--r-- 1 root root 151 Apr 28 04:40 logfile-04-20150427-23-00.log.gz
-rw-r--r-- 1 root root 161 Apr 28 05:14 logfile-04-20150428-04-00.log.gz
-rw-r--r-- 1 root root 134 Apr 28 06:45 logfile-04-20150428-05-00.log.gz
-rw-r--r-- 1 root root 125 Apr 28 08:46 logfile-04-20150428-06-00.log.gz
-rw-r--r-- 1 root root 191 Apr 28 09:27 logfile-04-20150428-08-00.log.gz
-rw-r--r-- 1 root root 281 Apr 28 10:43 logfile-04-20150428-09-00.log.gz
Clearly the logger is not rotating the logfile at the apt time. (see the modification time of the file and the logfile timestamp).
The following is my log4j2.xml configuration for the logger.
<RollingFile name="userlogfileAppender"
fileName="${sys:catalina.home}/webapps/miscLogs/uData/logfile/logfile.log"
filePattern="${sys:catalina.home}/webapps/miscLogs/uData/logfile/logfile-${logfileId}-%d{yyyyMMdd-HH}-00.log.gz"
immediateFlush="true"
bufferedIO="false">
<PatternLayout>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
<logger additivity="false" name="userlogfileLogger" level="debug">
<AppenderRef ref="userlogfileAppender"/>

Rollover is not driven by a timer in log4j2, but by log events. The rollover appender will compare the timestamp of the log event with the scheduled rollover time, and if the rollover time has been exceeded, then the file is rolled over.
This means that if traffic is sparse, there will often not be a log event that triggers a rollover at the scheduled rollover time. Rollover will occur at the next event after the scheduled rollover time, which may be hours later.
Log4j2 currently does not have a timer mechanism to force rollover. Depending on how mission-critical this is, you can create a timer in your application that logs an event once an hour to force a rollover.

Related

Lua can't import a module and says file not found but the file exists

i'm trying to run a lua script from inside haproxy that imports the "pgmoon" library. i can import pgmoon and get as far as opening a socket, but then i run into this:
[ALERT] 082/234313 (8) : Lua function 'queue-request': runtime error: /usr/local/share/lua/5.3/pgmoon/init.lua:269: module 'pgmoon.crypto' not found:
no field package.preload['pgmoon.crypto']
no file '/usr/local/share/lua/5.3/pgmoon/crypto.lua'
no file '/usr/local/share/lua/5.3/pgmoon/crypto/init.lua'
no file '/usr/local/lib/lua/5.3/pgmoon/crypto.lua'
no file '/usr/local/lib/lua/5.3/pgmoon/crypto/init.lua'
no file '/usr/share/lua/5.3/pgmoon/crypto.lua'
no file '/usr/share/lua/5.3/pgmoon/crypto/init.lua'
no file './pgmoon/crypto.lua'
no file './pgmoon/crypto/init.lua'
no file '/usr/local/lib/lua/5.3/pgmoon/crypto.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.3/pgmoon/crypto.so'
no file '/usr/lib/lua/5.3/pgmoon/crypto.so'
no file '/usr/local/lib/lua/5.3/loadall.so'
no file './pgmoon/crypto.so'
no file '/usr/local/lib/lua/5.3/pgmoon.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.3/pgmoon.so'
no file '/usr/lib/lua/5.3/pgmoon.so'
no file '/usr/local/lib/lua/5.3/loadall.so'
no file './pgmoon.so' from [C] global 'require', /usr/local/share/lua/5.3/pgmoon/init.lua:269 C function line 267 ..., /usr/local/share/lua/5.3/pgmoon/init.lua:211 method 'connect', /usr/local/haproxy/queue-request.lua:38 C function line 25.
however, there is a file at /usr/local/share/lua/5.3/pgmoon/crypto.lua, this is what ls shows:
# ls -la /usr/local/share/lua/5.3/pgmoon/
total 60
drwxr-xr-x 1 root root 4096 Mar 24 23:42 .
drwxr-xr-x 1 root root 4096 Mar 24 23:00 ..
-rw-r--r-- 1 root root 2880 Mar 24 23:00 arrays.lua
-rw-r--r-- 1 root root 1130 Mar 24 23:00 bit.lua
-rw-r--r-- 1 root root 1587 Mar 24 23:00 cqueues.lua
-rw-r--r-- 1 root root 654 Mar 24 23:00 crypto.lua
-rw-r--r-- 1 root root 2084 Mar 24 23:00 hstore.lua
-rw-r--r-- 1 root root 20127 Mar 24 23:00 init.lua
-rw-r--r-- 1 root root 665 Mar 24 23:00 json.lua
-rw-r--r-- 1 root root 2728 Mar 24 23:42 socket.lua
-rw-r--r-- 1 root root 457 Mar 24 23:00 util.lua
i could see it being permissions-related, if the haproxy user couldn't access a root owned file, but by the time it gets here it's already executed init.lua which has imported socket.lua and they've all got the same permissions...
Anybody know why lua thinks there is no file at crypto.lua?
I guess that you have haproxy configured with chroot and there actually isn't a file at /usr/local/share/lua/5.3/pgmoon/crypto.lua - in the chroot you haproxy runs in.
The require('pgmoon.crypto') in init.lua is within a function and probably tries to run long after Haproxy and lua initialization - and the root change.
And somewhat (un)relatedly - you can probably expect other problems with the pgmoon not being aware of haproxy, eg. its use of luasocket and not the haproxy-provided replacement: https://www.haproxy.com/blog/5-ways-to-extend-haproxy-with-lua/
The Socket class is a replacement for the standard Lua Socket class and is compatible with HAProxy’s non-blocking nature. When you want to use socket functions in your actions, you must use this class.

how to configure timebased logs and its compression policy

I have a requirement to write log files based on the hour.
Apart from the current log, rest of the logs should be compressed (gz), like below
-rw-r--r-- 1 karthick karthick 58546 Aug 31 19:00 console.20200831-19.log.gz
-rw-r--r-- 1 karthick karthick 58546 Aug 31 20:00 console.20200831-20.log.gz
-rw-r--r-- 1 karthick karthick 58546 Aug 31 21:00 console.20200831-21.log
Tried below snippet, but didn't worked as expected.
<RollingRandomAccessFile
name="myFile"
fileName="console.%d{yyyyMMdd-HH}.log"
filePattern="console.%d{yyyyMMdd-HH}.log.gz"
append="true" immediateFlush="true">
<PatternLayout pattern="%d [%t] %-5p %c[1] %m%n">
<Policies>
<TimeBasedTriggerPolicy>
<Policies>
</RollingRandomAccessFile>
You cannot have %{d} in the fileName, it is only used to create the target file at rollover. You could leave the fileName attribute off, however you should be aware that the file will not be compressed at shutdown and if the time is different at restart it won't be compressed then either.

Jenkins can't find artifacts

I have a jenkins running a job, after which I want it to "archive artifact", which is basically just get some files.
The Job clones a github and when ran, it generates some log files which I need.
The patter is:
logfiles/*
I added a command to list the directory to make sure the files are there, and indeed they are.
+ ls -la logfiles
total 24
drwxr-xr-x 2 root root 4096 Apr 22 23:23 .
drwxr-xr-x 8 root root 4096 Apr 22 23:23 ..
-rw-r--r-- 1 root root 0 Apr 22 23:23 1461367410777_testuuid_61746144-3A3A-5555-4944-3D5343414C41.log
-rw-r--r-- 1 root root 1248 Apr 22 23:23 1461367410777_testuuid_61746144-3A3A-5555-4944-3D5343414C41_shortmsg.csv
-rw-r--r-- 1 root root 2521 Apr 22 23:23 1461367410777_testuuid_61746144-3A3A-5555-4944-3D5343414C41_stats.log
-rw-r--r-- 1 root root 8035 Apr 22 23:23 1461367410777_testuuid_61746144-3A3A-5555-4944-3D5343414C41_trace_msg.log
Archiving artifacts
ERROR: No artifacts found that match the file pattern "logfiles/*". Configuration error?
ERROR: ‘logfiles/*’ doesn’t match anything, but ‘*’ does. Perhaps that’s what you mean?
Build step 'Archive the artifacts' changed build result to FAILURE
I don't really understand why they are not found.
Hope someone can help!
Thanks!
I finally found my problem. I had configured the job to do the git clone. But for some reason I also added the cloning on the build steps... once i removed that jenkins started getting the files properly.
I would still like to understand why this would happen...
Thanks to all

Why can't I use <date> selector on an ant <dirset>?

I have three files and three directories in a directory, with varying dates.
$ cd mydir
$ ls -ltr
-rw-rw-r-- 1 skiphoppy users 0 Nov 14 00:00 file.old.20121114
drwxrwxrwx 2 skiphoppy users 4096 Nov 14 00:00 dir.old.20121114
drwxrwxrwx 2 skiphoppy users 4096 Dec 5 12:05 dir.old.20121205
drwxrwxrwx 2 skiphoppy users 4096 Dec 5 12:05 dir
-rw-rw-r-- 1 skiphoppy users 0 Dec 5 12:16 file.old.20121205
-rw-rw-r-- 1 skiphoppy users 0 Dec 5 12:16 file
I want to build a dirset that includes all directories older than 2012-12-01. If I am reading right, the selector can be used to limit the files returned. But it appears this doesn't work for a dirset, even though the dirset documentation says you can use nested patternsets and selectors.
If I use the date selector on a fileset, I get just the one old file that I would expect; but with the same syntax on a dirset, I get all directories:
<fileset id="old.files" dir="mydir">
<date datetime="12/01/2012 12:00 AM" when="before"/>
</fileset>
<echo message="Files: ${toString:old.files}"/>
<dirset id="old.dirs" dir="mydir">
<date datetime="12/01/2012 12:00 AM" when="before"/>
</dirset>
<echo message="Dirs: ${toString:old.dirs}"/>
Output:
[echo] Files: file.old.20121114
[echo] Dirs: ;dir;dir.old.20121114;dir.old.20121205
What is going on here that the date selector does not work?
You probably need the checkdirs attribute set for the date selector. The default is 'false', i.e. select everything.
<date datetime="12/01/2012 12:00 AM" when="before" checkdirs="true" />

liferay page layout thumbnails not showing up

The issue is that I am not able to see thumbnails of the Page layouts. I am working on Liferay Portal EE 6.1.20.
When I go to Manage -> Page Layout, I cannot see the thumbnails.
Few things
I am not using OOB Liferay, it is a custom solution where Liferay is bundled as a custom portal solution
This thing works fine in Liferay OOB, so there must be some configuration issue
I tried to debug with Firebug and it is able to fetch the image from the URL specified.
The context path is changed from / to /portal
The generated image URL is like this /portal/layouttpl/custom/1_2_columns_ii.png. This is also not accessible from the browser itself.
The other URLS like /portal/html or /portal/wap/ working fine. Only from /portal/layouttpl does not allow to access static resources.
Any Idea?
It might be worth checking the file permissions of the images. In my Liferay development enviroment, I have all of my images set to 777:
user#ubuntu:/usr/liferay/tomcat/webapps/ROOT/layouttpl/custom$ ll *.png
-rwxrwxrwx 1 root root 1801 Apr 2 2012 1_2_1_columns.png*
-rwxrwxrwx 1 root root 1798 Apr 2 2012 1_2_columns_ii.png*
-rwxrwxrwx 1 root root 1793 Apr 2 2012 1_2_columns_i.png*
-rwxrwxrwx 1 root root 1425 Apr 2 2012 1_column.png*
-rwxrwxrwx 1 root root 1923 Apr 2 2012 2_2_columns.png*
-rwxrwxrwx 1 root root 1718 Apr 2 2012 2_columns_iii.png*
-rwxrwxrwx 1 root root 1735 Apr 2 2012 2_columns_ii.png*
-rwxrwxrwx 1 root root 1618 Apr 2 2012 2_columns_i.png*
-rwxrwxrwx 1 root root 1852 Apr 2 2012 3_columns.png*
-rwxrwxrwx 1 root root 1740 Apr 2 2012 freeform.png*

Resources