Add pylogfilename and pyloglevel functions to allow separating python logging. Unify recollinit calls

This commit is contained in:
Jean-Francois Dockes 2019-03-10 14:52:46 +01:00
parent 3b55d03b39
commit 20910d3911
9 changed files with 33 additions and 27 deletions

View File

@ -274,7 +274,8 @@ RclConfig *recollinit(int flags,
// to utf8 for indexing.
setlocale(LC_CTYPE, "");
Logger::getTheLog("")->setLogLevel(Logger::LLDEB1);
// Initially log to stderr, at error level.
Logger::getTheLog("")->setLogLevel(Logger::LLERR);
initAsyncSigs(sigcleanup);
@ -306,6 +307,14 @@ RclConfig *recollinit(int flags,
config->getConfParam(string("idxloglevel"), loglevel);
}
}
if (flags & RCLINIT_PYTHON) {
if (logfilename.empty()) {
config->getConfParam(string("pylogfilename"), logfilename);
}
if (loglevel.empty()) {
config->getConfParam(string("pyloglevel"), loglevel);
}
}
if (logfilename.empty())
config->getConfParam(string("logfilename"), logfilename);
@ -315,7 +324,7 @@ RclConfig *recollinit(int flags,
// Initialize logging
if (!logfilename.empty()) {
logfilename = path_tildexpand(logfilename);
// If not an absolute path or , compute relative to config dir
// If not an absolute path or stderr, compute relative to config dir.
if (!path_isabsolute(logfilename) &&
logfilename.compare("stderr")) {
logfilename = path_cat(config->getConfDir(), logfilename);
@ -372,7 +381,8 @@ RclConfig *recollinit(int flags,
int flushmb;
if (config->getConfParam("idxflushmb", &flushmb) && flushmb > 0) {
LOGDEB1("rclinit: idxflushmb=" << (flushmb) << ", set XAPIAN_FLUSH_THRESHOLD to 10E6\n" );
LOGDEB1("rclinit: idxflushmb=" << flushmb <<
", set XAPIAN_FLUSH_THRESHOLD to 10E6\n");
static const char *cp = "XAPIAN_FLUSH_THRESHOLD=1000000";
#ifdef PUTENV_ARG_CONST
::putenv(cp);

View File

@ -39,16 +39,11 @@ class RclConfig;
* default and environment
* @return the parsed configuration.
*/
enum RclInitFlags {RCLINIT_NONE = 0, RCLINIT_DAEMON = 1, RCLINIT_IDX = 2};
enum RclInitFlags {RCLINIT_NONE = 0, RCLINIT_DAEMON = 1, RCLINIT_IDX = 2,
RCLINIT_PYTHON = 4};
extern RclConfig *recollinit(int flags,
void (*cleanup)(void), void (*sigcleanup)(int),
std::string& reason, const std::string *argcnf = 0);
inline RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int),
std::string& reason,
const std::string *argcnf = 0)
{
return recollinit(RCLINIT_NONE, cleanup, sigcleanup, reason, argcnf);
}
// Threads need to call this to block signals.
// The main thread handles all signals.

View File

@ -35,7 +35,6 @@ using namespace std;
// Imported from pyrecoll
static PyObject *recoll_DocType;
static RclConfig *rclconfig;
//////////////////////////////////////////////////////////////////////
/// Extractor object code
@ -324,19 +323,21 @@ initrclextract(void)
#endif
{
// We run recollinit. It's responsible for initializing some static data
// which is distinct from pyrecoll's as we're separately dlopened
// which is distinct from pyrecoll's as we're separately dlopened.
// The rclconfig object is not used, we'll get the config
// data from the objects out of the recoll module.
// Unfortunately, as we're not getting the actual config directory
// from pyrecoll (we could, through a capsule), this needs at
// least an empty default configuration directory to work.
string reason;
rclconfig = recollinit(0, 0, reason, 0);
RclConfig *rclconfig = recollinit(RCLINIT_PYTHON, 0, 0, reason, 0);
if (rclconfig == 0) {
PyErr_SetString(PyExc_EnvironmentError, reason.c_str());
INITERROR;
} else {
delete rclconfig;
}
if (!rclconfig->ok()) {
PyErr_SetString(PyExc_EnvironmentError,
"Recoll init error: bad environment ?");
INITERROR;
}
#if PY_MAJOR_VERSION >= 3
PyObject *module = PyModule_Create(&moduledef);
#else

View File

@ -1576,9 +1576,9 @@ Db_init(recoll_DbObject *self, PyObject *args, PyObject *kwargs)
delete rclconfig;
if (confdir) {
string cfd = confdir;
rclconfig = recollinit(0, 0, reason, &cfd);
rclconfig = recollinit(RCLINIT_PYTHON, 0, 0, reason, &cfd);
} else {
rclconfig = recollinit(0, 0, reason, 0);
rclconfig = recollinit(RCLINIT_PYTHON, 0, 0, reason, 0);
}
LOGDEB("Db_init\n");

View File

@ -305,7 +305,7 @@ int main(int argc, char **argv)
string reason;
theconfig = recollinit(recollCleanup, 0, reason, &a_config);
theconfig = recollinit(0, recollCleanup, 0, reason, &a_config);
if (!theconfig || !theconfig->ok()) {
QString msg = "Configuration problem: ";
msg += QString::fromUtf8(reason.c_str());

View File

@ -248,7 +248,7 @@ int recollq(RclConfig **cfp, int argc, char **argv)
endopts:
string reason;
*cfp = recollinit(0, 0, reason, &a_config);
*cfp = recollinit(0, 0, 0, reason, &a_config);
RclConfig *rclconfig = *cfp;
if (!rclconfig || !rclconfig->ok()) {
fprintf(stderr, "Recoll init failed: %s\n", reason.c_str());

View File

@ -175,7 +175,7 @@ int main(int argc, const char **argv)
opt |= FsTreeWalker::FtwTravBreadthThenDepth;
string reason;
if (!recollinit(0, 0, reason)) {
if (!recollinit(0, 0, 0, reason)) {
fprintf(stderr, "Init failed: %s\n", reason.c_str());
exit(1);
}

View File

@ -23,7 +23,7 @@
using namespace std;
Logger::Logger(const std::string& fn)
: m_tocerr(false), m_loglevel(LLDEB), m_fn(fn)
: m_fn(fn)
{
reopen(fn);
}

View File

@ -81,8 +81,8 @@ public:
#endif
private:
bool m_tocerr;
int m_loglevel;
bool m_tocerr{false};
int m_loglevel{LLERR};
std::string m_fn;
std::ofstream m_stream;
#if LOGGER_THREADSAFE