Index: Lib/logging/__init__.py =================================================================== --- Lib/logging/__init__.py (revision 74916) +++ Lib/logging/__init__.py (working copy) @@ -1583,3 +1583,29 @@ if _warnings_showwarning is not None: warnings.showwarning = _warnings_showwarning _warnings_showwarning = None + +def _parse_python_options(options): + """ + This function will be called if the -l + command line argument is given to Python. + + The syntax is + python -l ... + where is a colon-separated list of = pairs. + + Examples: + python -l level=DEBUG ... + python -l 'level=DEBUG;format=%(asctime)-15s: %(message)s' ... + python -l level=DEBUG;filename=mylogfile.log ... + """ + import logging + kwds = {} + try: + for opt in options.split(";"): + opt = opt.strip() + o, a = opt.strip().split("=") + a = getattr(logging, a, a) + kwds[o] = a + logging.basicConfig(**kwds) + except Exception, details: + print "Error in logging options:", details Index: Modules/main.c =================================================================== --- Modules/main.c (revision 74916) +++ Modules/main.c (working copy) @@ -40,7 +40,7 @@ static int orig_argc; /* command line options */ -#define BASE_OPTS "3bBc:dEhiJm:OQ:sStuUvVW:xX?" +#define BASE_OPTS "3bBc:dEhiJm:OQ:sStuUvVW:xX?l:" #ifndef RISCOS #define PROGRAM_OPTS BASE_OPTS @@ -259,6 +259,7 @@ char *command = NULL; char *filename = NULL; char *module = NULL; + char *logopts = NULL; FILE *fp = stdin; char *p; int unbuffered = 0; @@ -321,6 +322,17 @@ Py_DivisionWarningFlag = 1; break; + case 'l': + if (logopts != NULL) + Py_FatalError( + "-l option may only be specified once"); + logopts = (char *)malloc(strlen(_PyOS_optarg) + 1); + if (logopts == NULL) + Py_FatalError( + "not enough memory to copy -l argument"); + strcpy(logopts, _PyOS_optarg); + break; + case 'Q': if (strcmp(_PyOS_optarg, "old") == 0) { Py_DivisionWarningFlag = 0; @@ -548,6 +560,22 @@ Py_DECREF(v); } + if (logopts != NULL) { + PyObject *v; + v = PyImport_ImportModule("logging"); + if (v == NULL) + PyErr_Print(); + else { + PyObject *result; + result = PyObject_CallMethod(v, "_parse_python_options", "s", logopts); + if (result) + Py_DECREF(result); + else + PyErr_Print(); + Py_DECREF(v); + } + } + if (command) { sts = PyRun_SimpleStringFlags(command, &cf) != 0; free(command);