Add pylogfilename and pyloglevel functions to allow separating python logging. Unify recollinit calls
This commit is contained in:
parent
3b55d03b39
commit
20910d3911
@ -274,7 +274,8 @@ RclConfig *recollinit(int flags,
|
|||||||
// to utf8 for indexing.
|
// to utf8 for indexing.
|
||||||
setlocale(LC_CTYPE, "");
|
setlocale(LC_CTYPE, "");
|
||||||
|
|
||||||
Logger::getTheLog("")->setLogLevel(Logger::LLDEB1);
|
// Initially log to stderr, at error level.
|
||||||
|
Logger::getTheLog("")->setLogLevel(Logger::LLERR);
|
||||||
|
|
||||||
initAsyncSigs(sigcleanup);
|
initAsyncSigs(sigcleanup);
|
||||||
|
|
||||||
@ -306,6 +307,14 @@ RclConfig *recollinit(int flags,
|
|||||||
config->getConfParam(string("idxloglevel"), loglevel);
|
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())
|
if (logfilename.empty())
|
||||||
config->getConfParam(string("logfilename"), logfilename);
|
config->getConfParam(string("logfilename"), logfilename);
|
||||||
@ -315,7 +324,7 @@ RclConfig *recollinit(int flags,
|
|||||||
// Initialize logging
|
// Initialize logging
|
||||||
if (!logfilename.empty()) {
|
if (!logfilename.empty()) {
|
||||||
logfilename = path_tildexpand(logfilename);
|
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) &&
|
if (!path_isabsolute(logfilename) &&
|
||||||
logfilename.compare("stderr")) {
|
logfilename.compare("stderr")) {
|
||||||
logfilename = path_cat(config->getConfDir(), logfilename);
|
logfilename = path_cat(config->getConfDir(), logfilename);
|
||||||
@ -372,7 +381,8 @@ RclConfig *recollinit(int flags,
|
|||||||
|
|
||||||
int flushmb;
|
int flushmb;
|
||||||
if (config->getConfParam("idxflushmb", &flushmb) && flushmb > 0) {
|
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";
|
static const char *cp = "XAPIAN_FLUSH_THRESHOLD=1000000";
|
||||||
#ifdef PUTENV_ARG_CONST
|
#ifdef PUTENV_ARG_CONST
|
||||||
::putenv(cp);
|
::putenv(cp);
|
||||||
|
|||||||
@ -39,16 +39,11 @@ class RclConfig;
|
|||||||
* default and environment
|
* default and environment
|
||||||
* @return the parsed configuration.
|
* @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,
|
extern RclConfig *recollinit(int flags,
|
||||||
void (*cleanup)(void), void (*sigcleanup)(int),
|
void (*cleanup)(void), void (*sigcleanup)(int),
|
||||||
std::string& reason, const std::string *argcnf = 0);
|
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.
|
// Threads need to call this to block signals.
|
||||||
// The main thread handles all signals.
|
// The main thread handles all signals.
|
||||||
|
|||||||
@ -35,7 +35,6 @@ using namespace std;
|
|||||||
|
|
||||||
// Imported from pyrecoll
|
// Imported from pyrecoll
|
||||||
static PyObject *recoll_DocType;
|
static PyObject *recoll_DocType;
|
||||||
static RclConfig *rclconfig;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
/// Extractor object code
|
/// Extractor object code
|
||||||
@ -324,19 +323,21 @@ initrclextract(void)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// We run recollinit. It's responsible for initializing some static data
|
// 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;
|
string reason;
|
||||||
rclconfig = recollinit(0, 0, reason, 0);
|
RclConfig *rclconfig = recollinit(RCLINIT_PYTHON, 0, 0, reason, 0);
|
||||||
if (rclconfig == 0) {
|
if (rclconfig == 0) {
|
||||||
PyErr_SetString(PyExc_EnvironmentError, reason.c_str());
|
PyErr_SetString(PyExc_EnvironmentError, reason.c_str());
|
||||||
INITERROR;
|
INITERROR;
|
||||||
|
} else {
|
||||||
|
delete rclconfig;
|
||||||
}
|
}
|
||||||
if (!rclconfig->ok()) {
|
|
||||||
PyErr_SetString(PyExc_EnvironmentError,
|
|
||||||
"Recoll init error: bad environment ?");
|
|
||||||
INITERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3
|
||||||
PyObject *module = PyModule_Create(&moduledef);
|
PyObject *module = PyModule_Create(&moduledef);
|
||||||
#else
|
#else
|
||||||
|
|||||||
@ -1576,9 +1576,9 @@ Db_init(recoll_DbObject *self, PyObject *args, PyObject *kwargs)
|
|||||||
delete rclconfig;
|
delete rclconfig;
|
||||||
if (confdir) {
|
if (confdir) {
|
||||||
string cfd = confdir;
|
string cfd = confdir;
|
||||||
rclconfig = recollinit(0, 0, reason, &cfd);
|
rclconfig = recollinit(RCLINIT_PYTHON, 0, 0, reason, &cfd);
|
||||||
} else {
|
} else {
|
||||||
rclconfig = recollinit(0, 0, reason, 0);
|
rclconfig = recollinit(RCLINIT_PYTHON, 0, 0, reason, 0);
|
||||||
}
|
}
|
||||||
LOGDEB("Db_init\n");
|
LOGDEB("Db_init\n");
|
||||||
|
|
||||||
|
|||||||
@ -305,7 +305,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
string reason;
|
string reason;
|
||||||
theconfig = recollinit(recollCleanup, 0, reason, &a_config);
|
theconfig = recollinit(0, recollCleanup, 0, reason, &a_config);
|
||||||
if (!theconfig || !theconfig->ok()) {
|
if (!theconfig || !theconfig->ok()) {
|
||||||
QString msg = "Configuration problem: ";
|
QString msg = "Configuration problem: ";
|
||||||
msg += QString::fromUtf8(reason.c_str());
|
msg += QString::fromUtf8(reason.c_str());
|
||||||
|
|||||||
@ -248,7 +248,7 @@ int recollq(RclConfig **cfp, int argc, char **argv)
|
|||||||
endopts:
|
endopts:
|
||||||
|
|
||||||
string reason;
|
string reason;
|
||||||
*cfp = recollinit(0, 0, reason, &a_config);
|
*cfp = recollinit(0, 0, 0, reason, &a_config);
|
||||||
RclConfig *rclconfig = *cfp;
|
RclConfig *rclconfig = *cfp;
|
||||||
if (!rclconfig || !rclconfig->ok()) {
|
if (!rclconfig || !rclconfig->ok()) {
|
||||||
fprintf(stderr, "Recoll init failed: %s\n", reason.c_str());
|
fprintf(stderr, "Recoll init failed: %s\n", reason.c_str());
|
||||||
|
|||||||
@ -175,7 +175,7 @@ int main(int argc, const char **argv)
|
|||||||
opt |= FsTreeWalker::FtwTravBreadthThenDepth;
|
opt |= FsTreeWalker::FtwTravBreadthThenDepth;
|
||||||
|
|
||||||
string reason;
|
string reason;
|
||||||
if (!recollinit(0, 0, reason)) {
|
if (!recollinit(0, 0, 0, reason)) {
|
||||||
fprintf(stderr, "Init failed: %s\n", reason.c_str());
|
fprintf(stderr, "Init failed: %s\n", reason.c_str());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Logger::Logger(const std::string& fn)
|
Logger::Logger(const std::string& fn)
|
||||||
: m_tocerr(false), m_loglevel(LLDEB), m_fn(fn)
|
: m_fn(fn)
|
||||||
{
|
{
|
||||||
reopen(fn);
|
reopen(fn);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,8 +81,8 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_tocerr;
|
bool m_tocerr{false};
|
||||||
int m_loglevel;
|
int m_loglevel{LLERR};
|
||||||
std::string m_fn;
|
std::string m_fn;
|
||||||
std::ofstream m_stream;
|
std::ofstream m_stream;
|
||||||
#if LOGGER_THREADSAFE
|
#if LOGGER_THREADSAFE
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user