Debian Bug report logs - #26543
A way to assign LOCALx facilities to some log files ?

version graph

Package: sysklogd; Maintainer for sysklogd is Martin Schulze <joey@debian.org>;

Reported by: Raphael Hertzog <rhertzog@hrnet.fr>

Date: Tue, 8 Sep 1998 12:18:02 UTC

Severity: wishlist

Found in version 1.3-26

Done: unknown

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#26543; Package sysklogd. Full text and rfc822 format available.

Acknowledgement sent to Raphael Hertzog <rhertzog@hrnet.fr>:
New bug report received and forwarded. Copy sent to Martin Schulze <joey@debian.org>. Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Raphael Hertzog <rhertzog@hrnet.fr>
To: submit@bugs.debian.org
Subject: A way to assign LOCALx facilities to some log files ?
Date: Tue, 8 Sep 1998 14:12:14 +0200
Package: sysklogd
Version: 1.3-26
Severity: wishlist

It would be nice to have a script which allow to assign a LOCALx facility
to a log file (or a pipe or a socket ...) because the policy forbids
another package to modify any conffiles from another package 
(like syslog.conf).

I propose such a script at the end of the mail. Look at some examples :
# ./syslog-facility set all /var/log/all                                        
It will output the name of the facility you have the right to use (ie local0)   
and adds a ligne to /etc/syslog.conf like that :                                
local0.*                /var/log/all                                            
                                                                                
But you can use more difficult things like :                                    
# ./syslog-facility set all\;\!=info /var/log/all-without-info                  
Idem it outputs something like "local0" and adds a line :
local0.*;local0.!=info          /var/log/all-without-info                       
                                                                                
Or :                                                                            
# ./syslog-facility set =err /var/log/errors =warning /var/log/warn             
It will add two lines :                                                         
local0.=err             /var/log/errors                                         
local0.=warning         /var/log/warn                                           
                                                                                
Etc. And you can remove any reference to "localx" facility with :               
# ./syslog-facility remove localx

It doesn't matter if you ship syslog.conf with     
a localx already used, the script will know that it cannot use it. I know       
PPP use local2 facility, the ppp maintainer doesn't need to change              
anything, it will work.

Here's the script (I don't attach it because the BTS is not mime-aware) :
------------------
#!/usr/bin/perl -w

my $conf_file = '/etc/syslog.conf';

## Copyright 1998 Hertzog Raphaël
## You can use this script under the term of the GPL v2 or later.

## BUGS :
#  . This script doesn't know about multi-lines configuration (ie with '\')
#  . With a line like that "mail,local0.* /anything" 
#    "syslog-facility remove local0" would remove the entire line
#    => should not be a problem since lines installed by this script
#    cannot use such syntax
##

## Nothing to modify after this line ##

my $command = lc(shift);

usage() if ($command !~ /^(?:set|remove)$/); 
usage() if (not scalar(@ARGV));

if ($command eq "set")
{
  usage() if (int(scalar(@ARGV) / 2) != scalar(@ARGV) / 2);
  # find a free localx facility
  my $facility = get_first_free_facility();
  # if none stop immediately
  if ($facility eq "none") {
    print "none\n";
    exit 1;
  }
  # ok append the lines asked
  open (CONF, ">>$conf_file") || 
        die "Can't open $conf_file in write mode: $!\n";
  my ($pri,$file,$line);
  while (defined($pri = shift)) {
    $file = shift;
    $line = "";
    foreach (split(/;/,$pri)) {
      $_ =~ s/all/*/g;
      $line .= ";" if ($line);
      $line .= "$facility.$_";
    }
    $line .= "\t\t$file\n";
    print CONF $line;
  }
  close CONF;
  print "$facility\n";
  exit 0;

} elsif ($command eq "remove") {

  my $facility = lc(shift);
  my ($left,$file,$line);
  open (CONF, $conf_file) || die "Can't open $conf_file: $!\n";
  open (CONFNEW, ">$conf_file.new")  || 
       die "Can't open $conf_file.new in write mode: $!\n";
  while (defined($_=<CONF>)) {
    # Write all "simple" lines like empty lines and comments
    if (/^\s*$/ or /^\s*#/ or /\\$/) {
      print CONFNEW $_;
      next;
    }
    # Otherwise look if the facility to remove appears in the line
    if (/^\s*(\S+)\s+(\S+)\s*/) {
      $left = $1; $file = $2; chomp $file;
      # It doesn't appers => write
      if ($left !~ /$facility/i) {
        print CONFNEW $_;
        next;
      }
      # It appears => write a new line without the localx facility
      $line = "";
      foreach (split(/;/,$left)) {
        if (not /$facility/i) {
          $line .= ";" if ($line);
          $line .= $_;
        }
      }
      next if ($line eq "");
      $line .= "\t\t$file\n";
      print CONFNEW $line;
    }
  }
  close CONFNEW;
  close CONF;
  rename ("$conf_file.new", "$conf_file");
}

sub get_first_free_facility {

   my @facility = (0) x 8;
   my ($left,$fac);
   open(CONF, $conf_file) || die "Can't open $conf_file: $!\n";
   while(defined($_=<CONF>))
   {
     next if (/^\s*$/);
     next if (/^\s*#/);
     next if (/\\$/);
     next if (not /^\s*(\S+)\s+(\S+)\s*$/);
     $left = $1;
     foreach $fac (split(/;/,$left))
     {
       $facility[$1]++ if ($fac =~ /local(\d)/i);
     }
   }
   foreach $fac (0..7)
   {
     return "local$fac" if ($facility[$fac] == 0);
   }
   return "none";
}

sub usage {

  die   "Usage : $0 set <set_of_priority> <logfile> ... \n"
       ."        it returns the 'LOCALx' string you have the right to use.\n"
       ."        $0 remove <facility>\n"
       ."Example: $0 set all /var/log/all\n"
       ."         $0 set all\\;\\!=info /var/log/all-without-info\n"
       ."         $0 set =err /var/log/errors =warning /var/log/warn\n"
       ."         $0 remove LOCAL1\n";   

}
-------------------

What you can change or add is to call "/etc/init.d/sysklogd reload" after
the modification of syslog.conf.

Cheers,
-- 
Hertzog Raphaël ¤ 0C4CABF1 ¤ http://www.mygale.org/~hra/


Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Sat Apr 19 18:17:19 2014; Machine Name: beach.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.