shadowm

Untitled

Oct 28th, 2012
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.60 KB | None | 0 0
  1. diff --git a/colordmesg b/colordmesg
  2. index faf8ac7..d5ffac2 100755
  3. --- a/colordmesg
  4. +++ b/colordmesg
  5. @@ -29,12 +29,11 @@ use constant {
  6.     KERN_EMERG      => 0,
  7.     KERN_ALERT      => 1,
  8.     KERN_CRIT       => 2,
  9. -   KERN_ERR        => 3,
  10. -   KERN_WARNING    => 4,
  11. -   KERN_NOTICE     => 5,
  12. -   KERN_INFO       => 6,
  13. -   KERN_DEBUG      => 7,
  14. -
  15. +   KERN_ERR        => 'err',
  16. +   KERN_WARNING    => 'warn',
  17. +   KERN_NOTICE     => 'notice',
  18. +   KERN_INFO       => 'info',
  19. +   KERN_DEBUG      => 'debug',
  20.     KERN_LAST       => 9,
  21.  };
  22.  
  23. @@ -42,28 +41,26 @@ use Term::ANSIColor qw(:constants);
  24.  
  25.  sub do_exit ($)   { exit($_[0] >> 8) }
  26.  sub abort ($$) { print STDERR $_[1]; do_exit($_[0]) }
  27. +sub trim (_) { $_[0] =~ s/^\s+//; $_[0] =~ s/\s+$//; $_[0] }
  28.  
  29. -open DMESG, '-|', join(' ', 'dmesg -r', @ARGV)
  30. +open DMESG, '-|', join(' ', 'dmesg -x', @ARGV)
  31.     or abort($?, "Pipe failed.\n");
  32.  
  33.  my $msgcolor;
  34.  
  35.  while(<DMESG>) {
  36. -   /^</ or print && next;
  37. -
  38. -   my ($level, $rts, $msg) = /^<(\d+)>(\[[.\s\d]+\])?(.*)$/;
  39. +   my ($facility, $level, $line) = map(trim, split(/\:/, $_, 3));
  40. +   my ($rts, $msg) = ($line =~ /^(\[[.\s\d]+\])?(.*)$/);
  41.  
  42. -   if($level > KERN_LAST) {
  43. -       ;
  44. -   } elsif($level > KERN_INFO) {
  45. +   if($level eq KERN_DEBUG) {
  46.         $msgcolor = BOLD.BLACK;
  47. -   } elsif($level == KERN_WARNING) {
  48. +   } elsif($level eq KERN_WARNING) {
  49.         $msgcolor = YELLOW;
  50. -   } elsif($level == KERN_ERR) {
  51. +   } elsif($level eq KERN_ERR) {
  52.         $msgcolor = BOLD.YELLOW;
  53. -   } elsif($level == KERN_CRIT) {
  54. +   } elsif($level eq KERN_CRIT) {
  55.         $msgcolor = RED;
  56. -   } elsif($level <= KERN_ALERT) {
  57. +   } elsif($level eq KERN_ALERT || $level eq KERN_EMERG) {
  58.         $msgcolor = BOLD.RED;
  59.     } else {
  60.         $msgcolor = '';
Advertisement
Add Comment
Please, Sign In to add comment