3

i have created a logrotate config file:

touch /etc/logrotate.d/.test

with the conficurations:

/home/myUser/test*.log{
    size 0
    hourly
    rotate 0    
    nocreate
    nocompress
    missingok
    nocopytruncate
    ifempty
}

I want to be able to clear the files after every entry (block log file) or in some log files to clear the last 'n' entries. Actualy, i want to keep doing:

truncate -s 0 /home/myUser/test*.log

As it is, nocopytruncate delete's the log files. If i put copytruncate it creates a second log of each log "test*.log.1", ignoring rotate 0. If i excecute the commands bellow doesn't do anything, ignoring size 0.

echo "hello" >> ~/test1.log
cat ~/test1.log
  //output: hello

Feels like it doesn't work by using size. For this to work, I need to excecute :

logrotate -f .test

Am I doing something wrong?

Is it possible to do this by using logrotate and keep the config file hidden somehow (as it is) ?

As for the 2nd part to clear last 'n' enries, I have no idea how can i do this with logrotate.

ioaniatr
  • 131
  • 1
  • 4
  • It won't work. Turn off logging in your app to send it to > /dev/null. logrotate isn't designed like this. It runs periodically so logs will still be written. – hookenz Mar 22 '17 at 22:08
  • Is there any other way to do this? I'm intreasting to do this even on common applications like apache, mysql e.t.c By clearing even every log in the system. – ioaniatr Mar 22 '17 at 22:11

1 Answers1

0

Instead of using logrotate.

I'd just do something like this:

ln -s /dev/null /home/myUser/test.log

Which will cause all logging data to go to the null device.

But logging is useful and normally you shouldn't just throw it away. Most apps allow you to modify how much they log and where they log to. I'd use those methods before just throwing them away.

hookenz
  • 14,472
  • 23
  • 88
  • 143
  • Imagine this to do it in `/var/log/*.log` . I think that this will cause a mesh. – ioaniatr Mar 22 '17 at 22:29
  • It'd be helpful to understand why you want to turf all your logs away. Is it an embedded device? it's usually easier to instruct apps not to log. – hookenz Mar 22 '17 at 22:39
  • If this is not possible with logrotate, maybe crontab with truncate? Not sure. – ioaniatr Mar 22 '17 at 23:05
  • You'd need to be a root user to logrotate /var/log for starters. And there is so much more you'd have to hide than just logfiles. In terms of turfing away original log files and preventing logging events from appearing I've answered that. You need a new question. – hookenz Mar 22 '17 at 23:13
  • If i excecute the command `ln -s /dev/null /var/log/*log` , can i restore this later? – ioaniatr Mar 24 '17 at 16:33