You are not logged in.

#1 2010-05-06 12:30:48

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Pacman log cleaner

I've written a script to clean up the pacman log file. (It was 32 MB on my system, mostly because Sage was built in the post_install function and thus spammed the log file.)

I've posted it on my site along with an explanation of what it does. (I've added syntax highlighting to my toolchain and wanted an excuse to use it. tongue)

Last edited by Xyne (2010-05-06 12:33:09)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#2 2010-05-06 13:04:36

jarryson
Member
Registered: 2007-02-18
Posts: 298

Re: Pacman log cleaner

i suggest to remove someting logs about "abc" package if there are both "installed abc" and "removed abc".

Offline

#3 2010-05-06 13:24:02

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Pacman log cleaner

Do you mean that it should remove e.g. "[YYYY-mm-dd HH:MM] removed abc (1.2.3)" and all entries related to "abc" before it?

I suppose I could add an option to do that.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#4 2010-05-06 14:29:39

Ogion
Member
From: Germany
Registered: 2007-12-11
Posts: 367

Re: Pacman log cleaner

Haven't tried the script (mainly because i don't want to mess with my logfile (and it's just 700k)) but i saw this on the description part:

The second argument is the path to the log file (default: /etc/pacman.log).

Syntax highlighting ftw though smile

Ogion

Last edited by Ogion (2010-05-06 14:30:09)


(my-dotfiles)
"People willing to trade their freedom for temporary security deserve neither and will lose both." - Benjamin Franklin
"Enlightenment is man's leaving his self-caused immaturity." - Immanuel Kant

Offline

#5 2010-05-06 14:51:42

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Pacman log cleaner

Personal style point, but I find

my $months = shift || 6;

to be much more readable than

my $months = @ARGV ? shift @ARGV : 6;

Offline

#6 2010-05-06 15:32:07

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Pacman log cleaner

@Ogion
If it's only 700k then there's obviously no need for this, but as already mentioned it doesn't change the log file.

and yeah, markdown + pandoc + source-highlight + some scripts = win (at least I'm happy with it)

@Daenyth
The example that you give will fail with all arguments that do not evaluate to "true" in a boolean context, which would thus prevent a user from using 0, which would be a valid argument.

I will admit that I hadn't even considered that form and I agree that it is nice and succinct, but the difference in readability is negligible for a Perl coder and debatable for others. I expect that implicit arguments would be a source of confusion for some, but so might the ternary operator, so meh.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#7 2010-05-06 16:10:41

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Pacman log cleaner

Ah, I hadn't considered that an argument of 0 would cause that to fail. Good catch smile

Aha, after looking into it further, what you want is // instead of ||. Short-circuit operator that's pretty much made for that exact use.

daenyth@Bragi ~ $ perl -E 'say shift || "fail"' 0
fail
daenyth@Bragi ~ $ perl -E 'say shift // "fail"' 0
0
daenyth@Bragi ~ $ perl -E 'say shift // "fail"'
fail

And yeah, ternary is ugly. As for implicit args, it's not required: "shift @ARGV // 6". Embrace the perlisms! big_smile

Last edited by Daenyth (2010-05-06 16:12:35)

Offline

#8 2010-05-06 16:52:03

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Pacman log cleaner

I'd never seen the "defined-or" operator before. I also found the "yada yada" operator while looking it up on perlop. smile

I've updated the script... now maybe we can focus on what it does instead of how it looks. wink


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#9 2010-05-06 16:56:42

archman-cro
Member
From: Croatia
Registered: 2010-04-04
Posts: 943
Website

Re: Pacman log cleaner

Hehe I wrote something similar to this one for myself a few days ago. It cleans the pacman.log of spam as "Synchronizing package databases..." and "Starting full system upgrade..." lines. smile
If anyone wants it, here it is...(author of the thread, if you find my post appropriate, please contact me or write here, and I will remove this code. smile)

sudo pacman -Syu &&
sudo sed -i '/starting full system upgrade/ d' /var/log/pacman.log &&
sudo sed -i '/synchronizing package lists/ d' /var/log/pacman.log &&
echo "==> log file cleared of spam messages" &&
echo "==> exit" &&
date +'%A, %d.%m.%y., %k:%M' > /home/<YOUR_USER_HERE>/.scripts/synched # or whatever you like

The last line is to keep track of when pacman was last synched.

Cheers. smile

Offline

Board footer

Powered by FluxBB