Jay Taylor's notes
back to listing indexRotating logs generated by a process that logs to stdin
[web search]I have a long running process, that writes its log file to stdout
. I would like to save this output to different files, automatically maintain these files (like deleting/archiving the old ones), without restarting the main process.
On solution would be to send the output to a file (process > log.txt
), and use logrotate
on it, but logrotate
needs to restart the program, which is not possible.
The other one is to pipe the output to cronolog
(process | cronolog
), but in this case older files won't get deleted / archived, meaning I have to make a program that will do the maintenance for me.
The best would be to be able to use both utilities, because with cronolog
I don't need to restart the process, and logrotate
will maintain the old log files exactly as I want. Is there a way to get these two programs to work with each other? If not, what is a good solution to this problem?
-
1
-
systemd and the journal should be able to fix this when they'll be available in production. systemd will redirect
stdout
to the journal and the journal will rotate the logs when needed. – Cristian Ciupitu Nov 3 '12 at 19:22
Multilog from DJB's daemontools can do (almost) exactly what you are asking. The only downside that I am aware of is that not many distributions carry a package for daemontools.
If you are not managing your application with svc
(part of the daemontools) you will have to find a way to pipe the output to a command like
multilog t s1048576 n100 ./my_log_directory
This translates to:
t
: insert a tai64n timestamp (that can be translated to readable time withtai64nlocal
)s1048576
: rotate the log file when it grows to 1MiBn100
: keep no more than 100 rotated files./my_log_directory
: anything starting with.
or/
- write the log to that directory
The log that is written will have the filename current
, and when multilog rotates the log, it will be renamed to @<tai64n timestamp>.s
where the filename shows the time when the file was rotated. The extension can be .s
if the file was safely flushed, or .u
if it may have been truncated.
For more info, just check the links.
-
Seems like the command I'm searching for. Fortunately it's available under Ubuntu: launchpad.net/ubuntu/+source/daemontools – SztupY Nov 5 '12 at 15:41
Your Answer
Not the answer you're looking for? Browse other questions tagged linux logging logrotate cronolog or ask your own question.
asked |
5 years, 5 months ago |
viewed |
2,259 times |
active |
Related
Hot Network Questions
-
How can I count files with a particular extension, and the directories they are in?
-
Whom & how to worship to develop fearless or fierce instincts?
-
How do I talk about my abusive former advisor if people ask?
-
Dealing with a major edgelord in a two-player campaign with awful party dynamics
-
How to execute library commands from the shell?
-
In US universities, are the sport coaches typically considered tenured professors?
-
How can hashes be unique if they are limited in number?
-
What to do about a colleague playing pranks on a manager?
-
Exit a query in a case statement?
-
If we sequenced the genome of every species, would all phylogenies agree?
-
Formula field in SOQL - Performance Impact
-
Can I reduce voltage from 3.3V to 1.8V using a 1.5V battery?
-
Confused by overtones when transcribing music
-
Is the Channel Tunnel in international waters?
-
A stamp kingdom rebus
-
What do "blacks" and "missions" refer to in this context?
-
“The heat button” or “the button of heat”
-
What is the difference between \paperheight, \paperwidth and \pdfpageheight, \pdfpagewidth?
-
Why do WiFi routers do such a bad job of channel selection?
site design / logo © 2018 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution required. rev 2018.4.9.29787