2005-04-27 05:59:47 +02:00
|
|
|
/*
|
|
|
|
* logging.c
|
|
|
|
*
|
|
|
|
* Simple logging functions that can be compiled away into nothing.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001-2003 Greg Kroah-Hartman <greg@kroah.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2003-09-25 05:56:17 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2005-04-27 05:59:47 +02:00
|
|
|
#include <syslog.h>
|
|
|
|
|
[PATCH] add udev logging to info log
On Thu, Jan 15, 2004 at 05:14:16AM +0100, Kay Sievers wrote:
> On Wed, Jan 14, 2004 at 01:10:43PM -0800, Greg KH wrote:
> > On Wed, Jan 14, 2004 at 02:34:26PM -0600, Clay Haapala wrote:
> > > On Wed, 14 Jan 2004, Chris Friesen spake thusly:
> > > >
> > > > Maybe for ones with a matching rule, you could print something like:
> > > >
> > > >
> > > Is the act of printing/syslogging a rule in an of itself?
> >
> > No, as currently the only way stuff ends up in the syslog is if
> > DEBUG=true is used on the build line.
> >
> > But it's sounding like we might want to change that... :)
>
> How about this in the syslog after connect/disconnect?
>
> Jan 15 05:07:45 pim udev[28007]: configured rule in '/etc/udev/udev.rules' at line 17 applied, 'video*' becomes 'video/webcam%n'
> Jan 15 05:07:45 pim udev[28007]: creating device node '/udev/video/webcam0'
> Jan 15 05:07:47 pim udev[28015]: removing device node '/udev/video/webcam0'
Here is a slightly better version. I've created a logging.h file and
moved the debug macros from udev.h in there.
If you type:
'make' - you will get a binary that prints one or two lines to syslog
if a device node is created or deleted
'make LOG=false' - you get a binary that prints asolutely nothing
'make DEBUG=true' - the same as today, it will print all debug lines
2004-01-16 06:53:20 +01:00
|
|
|
#include "logging.h"
|
|
|
|
|
2005-04-27 05:59:47 +02:00
|
|
|
|
|
|
|
static int logging_init = 0;
|
2003-09-25 05:56:17 +02:00
|
|
|
static unsigned char udev_logname[42];
|
2005-04-27 05:59:47 +02:00
|
|
|
|
2003-11-25 07:27:17 +01:00
|
|
|
static void init_logging(void)
|
2005-04-27 05:59:47 +02:00
|
|
|
{
|
2003-11-25 07:27:17 +01:00
|
|
|
snprintf(udev_logname, 42,"udev[%d]", getpid());
|
2003-09-25 05:56:17 +02:00
|
|
|
|
2003-11-25 07:27:17 +01:00
|
|
|
openlog(udev_logname, 0, LOG_DAEMON);
|
2005-04-27 05:59:47 +02:00
|
|
|
logging_init = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* log_message - sends a message to the logging facility
|
|
|
|
*/
|
2003-11-25 07:27:17 +01:00
|
|
|
int log_message(int level, const char *format, ...)
|
2005-04-27 05:59:47 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (!logging_init)
|
|
|
|
init_logging();
|
2003-11-25 07:27:17 +01:00
|
|
|
va_start(args, format);
|
|
|
|
vsyslog(level, format, args);
|
|
|
|
va_end(args);
|
2005-04-27 05:59:47 +02:00
|
|
|
return 1;
|
|
|
|
}
|