Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/colordmesg b/colordmesg
- index faf8ac7..d5ffac2 100755
- --- a/colordmesg
- +++ b/colordmesg
- @@ -29,12 +29,11 @@ use constant {
- KERN_EMERG => 0,
- KERN_ALERT => 1,
- KERN_CRIT => 2,
- - KERN_ERR => 3,
- - KERN_WARNING => 4,
- - KERN_NOTICE => 5,
- - KERN_INFO => 6,
- - KERN_DEBUG => 7,
- -
- + KERN_ERR => 'err',
- + KERN_WARNING => 'warn',
- + KERN_NOTICE => 'notice',
- + KERN_INFO => 'info',
- + KERN_DEBUG => 'debug',
- KERN_LAST => 9,
- };
- @@ -42,28 +41,26 @@ use Term::ANSIColor qw(:constants);
- sub do_exit ($) { exit($_[0] >> 8) }
- sub abort ($$) { print STDERR $_[1]; do_exit($_[0]) }
- +sub trim (_) { $_[0] =~ s/^\s+//; $_[0] =~ s/\s+$//; $_[0] }
- -open DMESG, '-|', join(' ', 'dmesg -r', @ARGV)
- +open DMESG, '-|', join(' ', 'dmesg -x', @ARGV)
- or abort($?, "Pipe failed.\n");
- my $msgcolor;
- while(<DMESG>) {
- - /^</ or print && next;
- -
- - my ($level, $rts, $msg) = /^<(\d+)>(\[[.\s\d]+\])?(.*)$/;
- + my ($facility, $level, $line) = map(trim, split(/\:/, $_, 3));
- + my ($rts, $msg) = ($line =~ /^(\[[.\s\d]+\])?(.*)$/);
- - if($level > KERN_LAST) {
- - ;
- - } elsif($level > KERN_INFO) {
- + if($level eq KERN_DEBUG) {
- $msgcolor = BOLD.BLACK;
- - } elsif($level == KERN_WARNING) {
- + } elsif($level eq KERN_WARNING) {
- $msgcolor = YELLOW;
- - } elsif($level == KERN_ERR) {
- + } elsif($level eq KERN_ERR) {
- $msgcolor = BOLD.YELLOW;
- - } elsif($level == KERN_CRIT) {
- + } elsif($level eq KERN_CRIT) {
- $msgcolor = RED;
- - } elsif($level <= KERN_ALERT) {
- + } elsif($level eq KERN_ALERT || $level eq KERN_EMERG) {
- $msgcolor = BOLD.RED;
- } else {
- $msgcolor = '';
Advertisement
Add Comment
Please, Sign In to add comment