Initial revision
[melted] / src / miracle / miracle_log.c
diff --git a/src/miracle/miracle_log.c b/src/miracle/miracle_log.c
new file mode 100644 (file)
index 0000000..cdb5d82
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * log.h -- logging facility implementation
+ * Copyright (C) 2002-2003 Ushodaya Enterprises Limited
+ * Author: Dan Dennedy <dan@dennedy.org>
+ *
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdarg.h>
+#include <syslog.h>
+#include <stdio.h>
+
+#include "log.h"
+
+static int log_output = log_stderr;
+static int threshold = LOG_DEBUG;
+
+void
+dv1394d_log_init( enum log_output method, int new_threshold )
+{
+       log_output = method;
+       threshold = new_threshold;
+       if (method == log_syslog)
+               openlog( "dv1394d", LOG_CONS, LOG_DAEMON );
+
+}
+
+void
+dv1394d_log( int priority, char *format, ... )
+{
+       va_list list;
+       va_start( list, format );
+       if ( LOG_PRI(priority) <= threshold )
+       {
+               if ( log_output == log_syslog )
+               {
+                               vsyslog( priority, format, list );
+               }
+               else
+               {
+                       char line[1024];
+                       if ( snprintf( line, 1024, "(%d) %s\n", priority, format ) != 0 )
+                               vfprintf( stderr, line, list );
+               }
+       }
+       va_end( list );
+}