Implemented a setup_logging() function that takes two keywords:
authorTim Potter <tpot@samba.org>
Thu, 11 Apr 2002 05:04:05 +0000 (05:04 +0000)
committerTim Potter <tpot@samba.org>
Thu, 11 Apr 2002 05:04:05 +0000 (05:04 +0000)
interactive and logfilename.  These can be used to send Samba DEBUG()
output to stdout or to a logfile which makes automated testing much
funkier.

Also added get_debuglevel() and set_debuglevel() functions.

source/python/py_common.c
source/python/py_common.h

index 5c2e0f896cda6de2ac1ed5b4143cdc2a31651290..bc3153c26cce53b1d30bfd134affd75527a52521 100644 (file)
@@ -46,10 +46,6 @@ void py_samba_init(void)
        if (initialised)
                return;
 
-       /* FIXME: logging doesn't work very well */
-
-       setup_logging("python", True);
-
        /* Load configuration file */
 
        if (!lp_load(dyn_CONFIGFILE, True, False, False))
@@ -58,7 +54,64 @@ void py_samba_init(void)
        /* Misc other stuff */
 
        load_interfaces();
-       DEBUGLEVEL = 10;
        
        initialised = True;
 }
+
+/* Debuglevel routines */
+
+PyObject *get_debuglevel(PyObject *self, PyObject *args)
+{
+       PyObject *debuglevel;
+
+       if (!PyArg_ParseTuple(args, ""))
+               return NULL;
+
+       debuglevel = PyInt_FromLong(DEBUGLEVEL);
+
+       return debuglevel;
+}
+
+PyObject *set_debuglevel(PyObject *self, PyObject *args)
+{
+       int debuglevel;
+
+       if (!PyArg_ParseTuple(args, "i", &debuglevel))
+               return NULL;
+
+       DEBUGLEVEL = debuglevel;
+
+       Py_INCREF(Py_None);
+       return Py_None;
+}
+
+/* Initialise logging */
+
+PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw)
+{
+       BOOL interactive = False;
+       char *logfilename = NULL;
+       static char *kwlist[] = {"interactive", "logfilename", NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kw, "|is", kwlist,
+                                        &interactive, &logfilename))
+               return NULL;
+       
+       if (interactive && logfilename) {
+               PyErr_SetString(PyExc_RuntimeError,
+                               "can't be interactive and set log file name");
+               return NULL;
+       }
+
+       if (interactive)
+               setup_logging("spoolss", True);
+
+       if (logfilename) {
+               lp_set_logfile(logfilename);
+               setup_logging(logfilename, False);
+               reopen_logs();
+       }
+
+       Py_INCREF(Py_None);
+       return Py_None;
+}
index 30a47eba25456163e849bacdddf6f76462d3df4b..4a5c92ca8cbb758358e0cfd1a88072f45017d8ff 100644 (file)
@@ -27,4 +27,8 @@ void py_samba_init(void);
 PyObject *py_werror_tuple(WERROR werror);
 PyObject *py_ntstatus_tuple(NTSTATUS ntstatus);
 
+PyObject *py_setup_logging(PyObject *self, PyObject *args);
+PyObject *get_debuglevel(PyObject *self, PyObject *args);
+PyObject *set_debuglevel(PyObject *self, PyObject *args);
+
 #endif /* _PY_COMMON_H */