How to combine logrotate with Log4j “rolling” file-appender?I want my logs sent to my mail with logrotateLogrotate Successful, original file goes back to original sizeHow to compress and clean logs with logrotate but not rotate themHow do I tell logrotate what files to rotate with cron?Logrotate: rotate all log files on specific size and rotate hourlyLogrotate doesn't work from cron on CentOSlogrotate cron job not rotating certain logsError with gunzip during logrotateDaily logrotate error creating unique temp file: Permission deniedLogs are not deleted and compressed in elasticsearch nodes
Multi tool use
Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?
To string or not to string
Do VLANs within a subnet need to have their own subnet for router on a stick?
TGV timetables / schedules?
Writing rule stating superpower from different root cause is bad writing
What do you call a Matrix-like slowdown and camera movement effect?
How to format long polynomial?
How can bays and straits be determined in a procedurally generated map?
Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)
What defenses are there against being summoned by the Gate spell?
What's the point of deactivating Num Lock on login screens?
Why are electrically insulating heatsinks so rare? Is it just cost?
Do I have a twin with permutated remainders?
What is the offset in a seaplane's hull?
How does one intimidate enemies without having the capacity for violence?
Why do falling prices hurt debtors?
How old can references or sources in a thesis be?
Problem of parity - Can we draw a closed path made up of 20 line segments...
Fencing style for blades that can attack from a distance
Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)
Can I ask the recruiters in my resume to put the reason why I am rejected?
Font hinting is lost in Chrome-like browsers (for some languages )
How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?
Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?
How to combine logrotate with Log4j “rolling” file-appender?
I want my logs sent to my mail with logrotateLogrotate Successful, original file goes back to original sizeHow to compress and clean logs with logrotate but not rotate themHow do I tell logrotate what files to rotate with cron?Logrotate: rotate all log files on specific size and rotate hourlyLogrotate doesn't work from cron on CentOSlogrotate cron job not rotating certain logsError with gunzip during logrotateDaily logrotate error creating unique temp file: Permission deniedLogs are not deleted and compressed in elasticsearch nodes
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
We have a Java-application, that uses log4j and rotates its own logs daily:
- The currently-used log-file is
/var/log/foo/foo.log
- It is moved into
/var/log/foo/foo.log.YYYY-MM-dd
when the day changes
We'd rather not change its configuration...
However, we do want to:
- Compress the file once it has been renamed
- Only retain a certain number of them
Though it wouldn't be difficult to write a cron-job to do both, we'd rather stay in the framework of logrotate
...
I create the following /etc/logrotate.d/foo
:
/var/log/foo/foo.log.*
daily
rotate 2
compress
delaycompress
missingok
notifempty
but it does not do anything:
reading config file /etc/logrotate.d/foo
Handling 1 logs
rotating pattern: /var/log/foo/foo.log.* after 1 days (2 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/foo/foo.log.2017-06-28
log does not need rotating
considering log /var/log/foo/foo.log.2017-06-29
log does not need rotating
considering log /var/log/foo/foo.log.2017-06-30
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-01
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-02
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-03
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-04
log does not need rotating
How do I make it compress the files and delete the oldest ones, when their total number exceeds 2?
logrotate log4j
add a comment |
We have a Java-application, that uses log4j and rotates its own logs daily:
- The currently-used log-file is
/var/log/foo/foo.log
- It is moved into
/var/log/foo/foo.log.YYYY-MM-dd
when the day changes
We'd rather not change its configuration...
However, we do want to:
- Compress the file once it has been renamed
- Only retain a certain number of them
Though it wouldn't be difficult to write a cron-job to do both, we'd rather stay in the framework of logrotate
...
I create the following /etc/logrotate.d/foo
:
/var/log/foo/foo.log.*
daily
rotate 2
compress
delaycompress
missingok
notifempty
but it does not do anything:
reading config file /etc/logrotate.d/foo
Handling 1 logs
rotating pattern: /var/log/foo/foo.log.* after 1 days (2 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/foo/foo.log.2017-06-28
log does not need rotating
considering log /var/log/foo/foo.log.2017-06-29
log does not need rotating
considering log /var/log/foo/foo.log.2017-06-30
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-01
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-02
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-03
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-04
log does not need rotating
How do I make it compress the files and delete the oldest ones, when their total number exceeds 2?
logrotate log4j
add a comment |
We have a Java-application, that uses log4j and rotates its own logs daily:
- The currently-used log-file is
/var/log/foo/foo.log
- It is moved into
/var/log/foo/foo.log.YYYY-MM-dd
when the day changes
We'd rather not change its configuration...
However, we do want to:
- Compress the file once it has been renamed
- Only retain a certain number of them
Though it wouldn't be difficult to write a cron-job to do both, we'd rather stay in the framework of logrotate
...
I create the following /etc/logrotate.d/foo
:
/var/log/foo/foo.log.*
daily
rotate 2
compress
delaycompress
missingok
notifempty
but it does not do anything:
reading config file /etc/logrotate.d/foo
Handling 1 logs
rotating pattern: /var/log/foo/foo.log.* after 1 days (2 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/foo/foo.log.2017-06-28
log does not need rotating
considering log /var/log/foo/foo.log.2017-06-29
log does not need rotating
considering log /var/log/foo/foo.log.2017-06-30
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-01
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-02
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-03
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-04
log does not need rotating
How do I make it compress the files and delete the oldest ones, when their total number exceeds 2?
logrotate log4j
We have a Java-application, that uses log4j and rotates its own logs daily:
- The currently-used log-file is
/var/log/foo/foo.log
- It is moved into
/var/log/foo/foo.log.YYYY-MM-dd
when the day changes
We'd rather not change its configuration...
However, we do want to:
- Compress the file once it has been renamed
- Only retain a certain number of them
Though it wouldn't be difficult to write a cron-job to do both, we'd rather stay in the framework of logrotate
...
I create the following /etc/logrotate.d/foo
:
/var/log/foo/foo.log.*
daily
rotate 2
compress
delaycompress
missingok
notifempty
but it does not do anything:
reading config file /etc/logrotate.d/foo
Handling 1 logs
rotating pattern: /var/log/foo/foo.log.* after 1 days (2 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/foo/foo.log.2017-06-28
log does not need rotating
considering log /var/log/foo/foo.log.2017-06-29
log does not need rotating
considering log /var/log/foo/foo.log.2017-06-30
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-01
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-02
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-03
log does not need rotating
considering log /var/log/foo/foo.log.2017-07-04
log does not need rotating
How do I make it compress the files and delete the oldest ones, when their total number exceeds 2?
logrotate log4j
logrotate log4j
edited Dec 25 '18 at 11:19
kasperd
26.8k1252104
26.8k1252104
asked Jul 5 '17 at 20:05
Mikhail T.Mikhail T.
1,4491431
1,4491431
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
I really don't think you are going be able to do what you want with logrotate
without some external commands. Also, the pattern /var/log/foo/foo.log.*
would treat each individual file as if it was a separate log to be rotated, not as a set of rotated files.
man logrotate
Please use wildcards with caution. If you specify *, logrotate will rotate all files, including previously rotated ones.
Anyway, maybe something like this? Just set your rotate condition that will never be reached since log4j is already handling the rotation partly. Then put the rest in a prerotate
script?
/var/log/foo/foo.log
size 100G # something big that will never be reached/rotated since log4j does this.
missingok
notifempty
# delete the other logs over 7 days old
prerotate
find /var/log/foo/ -name 'foo.log.*' -mtime +7 -delete
nice gzip /var/log/foo/foo.log.*
endscript
Thanks. This just seems like a way to execute arbitrary command -- there is nothinglogrotate
-ish about it :) I may as well just do a cron-job instead...
– Mikhail T.
Jul 5 '17 at 20:51
Yeah, like I said, I don't think you are going to find what you want.
– Zoredache
Jul 5 '17 at 21:52
Setting an unreachable rotate option doesn't work,logrotate
script options (e.g.prerotate
) are only run if at least one file is rotated (seeman logrotate
). I came up with a solution and posted it below.
– Ryan Fisher
Apr 3 at 19:09
add a comment |
I needed to accomplish this behavior because the app teams wanted to maintain control of log and filename format as well as rotation schedule with log4j. If you read man logrotate
you'll notice that all the pre/post/lastaction scripts only execute when at least one log was rotated. Thus, setting something unreachable like size 999G
does not work.
Instead, what I did was set the copy
and extension
options so that:
- The original log file was never touched (it's managed by log4j)
- The logs rotated by logrotate have a different extension that I can filter on
/var/log/<service>/<service>.log
copy # don't touch the orig. log file, it's managed by log4j
extension .log # End rotated files in ".log" so we can find and delete them
rotate 1
hourly
missingok
prerotate
find /var/log/<service>/ -iname "*service.log.*" ! -iname "*.gz" -exec gzip ; &&
aws s3 sync /var/log/<service>/ s3://<bucket>/<environment>/<ec2_id>/<service>/ --exclude "*" --include "*<service>*.gz" &&
find /var/log/<service>/ -iname "*<service>.log.*" -mtime +7 -delete
endscript
lastaction
find /var/log/<service>/ -iname "*<service>.*.log" -delete
endscript
Yes, I could just make a cron job. My reasoning for using logrotate
is that I keep all of the log rotation config management in a single Ansible role and in the future, I'll be making the case to disable log4j
rotation and use logrotate
instead which will be a simple change.
add a comment |
The Log4j Rolling File Appenders and the logrotate are not compatible. The log4j rotation will interfere with logrotate.
First you need to find the log4j configuration file for the application and replace the Rolling File Appenders with simple File Appenders. This will stop the log4j from rotating the files. Then you can use the logrotate to rotate the log files as you wanted.
If you can't modify the application's log4j configuration you can create your own one and specify this in the classpath when the application is stared.
-Dlog4j.configurationFile=path/to/log4j2.xml
Ref: https://logging.apache.org/log4j/2.0/faq.html#config_location
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f859561%2fhow-to-combine-logrotate-with-log4j-rolling-file-appender%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I really don't think you are going be able to do what you want with logrotate
without some external commands. Also, the pattern /var/log/foo/foo.log.*
would treat each individual file as if it was a separate log to be rotated, not as a set of rotated files.
man logrotate
Please use wildcards with caution. If you specify *, logrotate will rotate all files, including previously rotated ones.
Anyway, maybe something like this? Just set your rotate condition that will never be reached since log4j is already handling the rotation partly. Then put the rest in a prerotate
script?
/var/log/foo/foo.log
size 100G # something big that will never be reached/rotated since log4j does this.
missingok
notifempty
# delete the other logs over 7 days old
prerotate
find /var/log/foo/ -name 'foo.log.*' -mtime +7 -delete
nice gzip /var/log/foo/foo.log.*
endscript
Thanks. This just seems like a way to execute arbitrary command -- there is nothinglogrotate
-ish about it :) I may as well just do a cron-job instead...
– Mikhail T.
Jul 5 '17 at 20:51
Yeah, like I said, I don't think you are going to find what you want.
– Zoredache
Jul 5 '17 at 21:52
Setting an unreachable rotate option doesn't work,logrotate
script options (e.g.prerotate
) are only run if at least one file is rotated (seeman logrotate
). I came up with a solution and posted it below.
– Ryan Fisher
Apr 3 at 19:09
add a comment |
I really don't think you are going be able to do what you want with logrotate
without some external commands. Also, the pattern /var/log/foo/foo.log.*
would treat each individual file as if it was a separate log to be rotated, not as a set of rotated files.
man logrotate
Please use wildcards with caution. If you specify *, logrotate will rotate all files, including previously rotated ones.
Anyway, maybe something like this? Just set your rotate condition that will never be reached since log4j is already handling the rotation partly. Then put the rest in a prerotate
script?
/var/log/foo/foo.log
size 100G # something big that will never be reached/rotated since log4j does this.
missingok
notifempty
# delete the other logs over 7 days old
prerotate
find /var/log/foo/ -name 'foo.log.*' -mtime +7 -delete
nice gzip /var/log/foo/foo.log.*
endscript
Thanks. This just seems like a way to execute arbitrary command -- there is nothinglogrotate
-ish about it :) I may as well just do a cron-job instead...
– Mikhail T.
Jul 5 '17 at 20:51
Yeah, like I said, I don't think you are going to find what you want.
– Zoredache
Jul 5 '17 at 21:52
Setting an unreachable rotate option doesn't work,logrotate
script options (e.g.prerotate
) are only run if at least one file is rotated (seeman logrotate
). I came up with a solution and posted it below.
– Ryan Fisher
Apr 3 at 19:09
add a comment |
I really don't think you are going be able to do what you want with logrotate
without some external commands. Also, the pattern /var/log/foo/foo.log.*
would treat each individual file as if it was a separate log to be rotated, not as a set of rotated files.
man logrotate
Please use wildcards with caution. If you specify *, logrotate will rotate all files, including previously rotated ones.
Anyway, maybe something like this? Just set your rotate condition that will never be reached since log4j is already handling the rotation partly. Then put the rest in a prerotate
script?
/var/log/foo/foo.log
size 100G # something big that will never be reached/rotated since log4j does this.
missingok
notifempty
# delete the other logs over 7 days old
prerotate
find /var/log/foo/ -name 'foo.log.*' -mtime +7 -delete
nice gzip /var/log/foo/foo.log.*
endscript
I really don't think you are going be able to do what you want with logrotate
without some external commands. Also, the pattern /var/log/foo/foo.log.*
would treat each individual file as if it was a separate log to be rotated, not as a set of rotated files.
man logrotate
Please use wildcards with caution. If you specify *, logrotate will rotate all files, including previously rotated ones.
Anyway, maybe something like this? Just set your rotate condition that will never be reached since log4j is already handling the rotation partly. Then put the rest in a prerotate
script?
/var/log/foo/foo.log
size 100G # something big that will never be reached/rotated since log4j does this.
missingok
notifempty
# delete the other logs over 7 days old
prerotate
find /var/log/foo/ -name 'foo.log.*' -mtime +7 -delete
nice gzip /var/log/foo/foo.log.*
endscript
edited Apr 3 at 19:02
Ryan Fisher
1387
1387
answered Jul 5 '17 at 20:47
ZoredacheZoredache
112k30231379
112k30231379
Thanks. This just seems like a way to execute arbitrary command -- there is nothinglogrotate
-ish about it :) I may as well just do a cron-job instead...
– Mikhail T.
Jul 5 '17 at 20:51
Yeah, like I said, I don't think you are going to find what you want.
– Zoredache
Jul 5 '17 at 21:52
Setting an unreachable rotate option doesn't work,logrotate
script options (e.g.prerotate
) are only run if at least one file is rotated (seeman logrotate
). I came up with a solution and posted it below.
– Ryan Fisher
Apr 3 at 19:09
add a comment |
Thanks. This just seems like a way to execute arbitrary command -- there is nothinglogrotate
-ish about it :) I may as well just do a cron-job instead...
– Mikhail T.
Jul 5 '17 at 20:51
Yeah, like I said, I don't think you are going to find what you want.
– Zoredache
Jul 5 '17 at 21:52
Setting an unreachable rotate option doesn't work,logrotate
script options (e.g.prerotate
) are only run if at least one file is rotated (seeman logrotate
). I came up with a solution and posted it below.
– Ryan Fisher
Apr 3 at 19:09
Thanks. This just seems like a way to execute arbitrary command -- there is nothing
logrotate
-ish about it :) I may as well just do a cron-job instead...– Mikhail T.
Jul 5 '17 at 20:51
Thanks. This just seems like a way to execute arbitrary command -- there is nothing
logrotate
-ish about it :) I may as well just do a cron-job instead...– Mikhail T.
Jul 5 '17 at 20:51
Yeah, like I said, I don't think you are going to find what you want.
– Zoredache
Jul 5 '17 at 21:52
Yeah, like I said, I don't think you are going to find what you want.
– Zoredache
Jul 5 '17 at 21:52
Setting an unreachable rotate option doesn't work,
logrotate
script options (e.g. prerotate
) are only run if at least one file is rotated (see man logrotate
). I came up with a solution and posted it below.– Ryan Fisher
Apr 3 at 19:09
Setting an unreachable rotate option doesn't work,
logrotate
script options (e.g. prerotate
) are only run if at least one file is rotated (see man logrotate
). I came up with a solution and posted it below.– Ryan Fisher
Apr 3 at 19:09
add a comment |
I needed to accomplish this behavior because the app teams wanted to maintain control of log and filename format as well as rotation schedule with log4j. If you read man logrotate
you'll notice that all the pre/post/lastaction scripts only execute when at least one log was rotated. Thus, setting something unreachable like size 999G
does not work.
Instead, what I did was set the copy
and extension
options so that:
- The original log file was never touched (it's managed by log4j)
- The logs rotated by logrotate have a different extension that I can filter on
/var/log/<service>/<service>.log
copy # don't touch the orig. log file, it's managed by log4j
extension .log # End rotated files in ".log" so we can find and delete them
rotate 1
hourly
missingok
prerotate
find /var/log/<service>/ -iname "*service.log.*" ! -iname "*.gz" -exec gzip ; &&
aws s3 sync /var/log/<service>/ s3://<bucket>/<environment>/<ec2_id>/<service>/ --exclude "*" --include "*<service>*.gz" &&
find /var/log/<service>/ -iname "*<service>.log.*" -mtime +7 -delete
endscript
lastaction
find /var/log/<service>/ -iname "*<service>.*.log" -delete
endscript
Yes, I could just make a cron job. My reasoning for using logrotate
is that I keep all of the log rotation config management in a single Ansible role and in the future, I'll be making the case to disable log4j
rotation and use logrotate
instead which will be a simple change.
add a comment |
I needed to accomplish this behavior because the app teams wanted to maintain control of log and filename format as well as rotation schedule with log4j. If you read man logrotate
you'll notice that all the pre/post/lastaction scripts only execute when at least one log was rotated. Thus, setting something unreachable like size 999G
does not work.
Instead, what I did was set the copy
and extension
options so that:
- The original log file was never touched (it's managed by log4j)
- The logs rotated by logrotate have a different extension that I can filter on
/var/log/<service>/<service>.log
copy # don't touch the orig. log file, it's managed by log4j
extension .log # End rotated files in ".log" so we can find and delete them
rotate 1
hourly
missingok
prerotate
find /var/log/<service>/ -iname "*service.log.*" ! -iname "*.gz" -exec gzip ; &&
aws s3 sync /var/log/<service>/ s3://<bucket>/<environment>/<ec2_id>/<service>/ --exclude "*" --include "*<service>*.gz" &&
find /var/log/<service>/ -iname "*<service>.log.*" -mtime +7 -delete
endscript
lastaction
find /var/log/<service>/ -iname "*<service>.*.log" -delete
endscript
Yes, I could just make a cron job. My reasoning for using logrotate
is that I keep all of the log rotation config management in a single Ansible role and in the future, I'll be making the case to disable log4j
rotation and use logrotate
instead which will be a simple change.
add a comment |
I needed to accomplish this behavior because the app teams wanted to maintain control of log and filename format as well as rotation schedule with log4j. If you read man logrotate
you'll notice that all the pre/post/lastaction scripts only execute when at least one log was rotated. Thus, setting something unreachable like size 999G
does not work.
Instead, what I did was set the copy
and extension
options so that:
- The original log file was never touched (it's managed by log4j)
- The logs rotated by logrotate have a different extension that I can filter on
/var/log/<service>/<service>.log
copy # don't touch the orig. log file, it's managed by log4j
extension .log # End rotated files in ".log" so we can find and delete them
rotate 1
hourly
missingok
prerotate
find /var/log/<service>/ -iname "*service.log.*" ! -iname "*.gz" -exec gzip ; &&
aws s3 sync /var/log/<service>/ s3://<bucket>/<environment>/<ec2_id>/<service>/ --exclude "*" --include "*<service>*.gz" &&
find /var/log/<service>/ -iname "*<service>.log.*" -mtime +7 -delete
endscript
lastaction
find /var/log/<service>/ -iname "*<service>.*.log" -delete
endscript
Yes, I could just make a cron job. My reasoning for using logrotate
is that I keep all of the log rotation config management in a single Ansible role and in the future, I'll be making the case to disable log4j
rotation and use logrotate
instead which will be a simple change.
I needed to accomplish this behavior because the app teams wanted to maintain control of log and filename format as well as rotation schedule with log4j. If you read man logrotate
you'll notice that all the pre/post/lastaction scripts only execute when at least one log was rotated. Thus, setting something unreachable like size 999G
does not work.
Instead, what I did was set the copy
and extension
options so that:
- The original log file was never touched (it's managed by log4j)
- The logs rotated by logrotate have a different extension that I can filter on
/var/log/<service>/<service>.log
copy # don't touch the orig. log file, it's managed by log4j
extension .log # End rotated files in ".log" so we can find and delete them
rotate 1
hourly
missingok
prerotate
find /var/log/<service>/ -iname "*service.log.*" ! -iname "*.gz" -exec gzip ; &&
aws s3 sync /var/log/<service>/ s3://<bucket>/<environment>/<ec2_id>/<service>/ --exclude "*" --include "*<service>*.gz" &&
find /var/log/<service>/ -iname "*<service>.log.*" -mtime +7 -delete
endscript
lastaction
find /var/log/<service>/ -iname "*<service>.*.log" -delete
endscript
Yes, I could just make a cron job. My reasoning for using logrotate
is that I keep all of the log rotation config management in a single Ansible role and in the future, I'll be making the case to disable log4j
rotation and use logrotate
instead which will be a simple change.
edited 2 days ago
answered Apr 3 at 18:44
Ryan FisherRyan Fisher
1387
1387
add a comment |
add a comment |
The Log4j Rolling File Appenders and the logrotate are not compatible. The log4j rotation will interfere with logrotate.
First you need to find the log4j configuration file for the application and replace the Rolling File Appenders with simple File Appenders. This will stop the log4j from rotating the files. Then you can use the logrotate to rotate the log files as you wanted.
If you can't modify the application's log4j configuration you can create your own one and specify this in the classpath when the application is stared.
-Dlog4j.configurationFile=path/to/log4j2.xml
Ref: https://logging.apache.org/log4j/2.0/faq.html#config_location
add a comment |
The Log4j Rolling File Appenders and the logrotate are not compatible. The log4j rotation will interfere with logrotate.
First you need to find the log4j configuration file for the application and replace the Rolling File Appenders with simple File Appenders. This will stop the log4j from rotating the files. Then you can use the logrotate to rotate the log files as you wanted.
If you can't modify the application's log4j configuration you can create your own one and specify this in the classpath when the application is stared.
-Dlog4j.configurationFile=path/to/log4j2.xml
Ref: https://logging.apache.org/log4j/2.0/faq.html#config_location
add a comment |
The Log4j Rolling File Appenders and the logrotate are not compatible. The log4j rotation will interfere with logrotate.
First you need to find the log4j configuration file for the application and replace the Rolling File Appenders with simple File Appenders. This will stop the log4j from rotating the files. Then you can use the logrotate to rotate the log files as you wanted.
If you can't modify the application's log4j configuration you can create your own one and specify this in the classpath when the application is stared.
-Dlog4j.configurationFile=path/to/log4j2.xml
Ref: https://logging.apache.org/log4j/2.0/faq.html#config_location
The Log4j Rolling File Appenders and the logrotate are not compatible. The log4j rotation will interfere with logrotate.
First you need to find the log4j configuration file for the application and replace the Rolling File Appenders with simple File Appenders. This will stop the log4j from rotating the files. Then you can use the logrotate to rotate the log files as you wanted.
If you can't modify the application's log4j configuration you can create your own one and specify this in the classpath when the application is stared.
-Dlog4j.configurationFile=path/to/log4j2.xml
Ref: https://logging.apache.org/log4j/2.0/faq.html#config_location
answered Mar 11 at 9:56
Oz.Oz.
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f859561%2fhow-to-combine-logrotate-with-log4j-rolling-file-appender%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
YyEvxf6277U Yf1o we,K9wprtNX