allow daemon-specific log parameters

This commit is contained in:
dockes 2006-11-08 07:22:14 +00:00
parent 1205b11f60
commit 70f45f8746
3 changed files with 61 additions and 19 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rclinit.cpp,v 1.6 2006-09-08 09:02:47 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: rclinit.cpp,v 1.7 2006-11-08 07:22:14 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -25,22 +25,23 @@ static char rcsid[] = "@(#$Id: rclinit.cpp,v 1.6 2006-09-08 09:02:47 dockes Exp
#include "debuglog.h"
#include "rclconfig.h"
#include "rclinit.h"
#include "pathut.h"
RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int),
static const int catchedSigs[] = {SIGHUP, SIGINT, SIGQUIT, SIGTERM};
RclConfig *recollinit(RclInitFlags flags,
void (*cleanup)(void), void (*sigcleanup)(int),
string &reason, const string *argcnf)
{
if (cleanup)
atexit(cleanup);
if (sigcleanup) {
if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
signal(SIGHUP, sigcleanup);
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
signal(SIGINT, sigcleanup);
if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
signal(SIGQUIT, sigcleanup);
if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
signal(SIGTERM, sigcleanup);
for (unsigned int i = 0; i < sizeof(catchedSigs) / sizeof(int); i++)
if (signal(catchedSigs[i], SIG_IGN) != SIG_IGN)
signal(catchedSigs[i], sigcleanup);
}
DebugLog::getdbl()->setloglevel(DEBDEB1);
DebugLog::setfilename("stderr");
RclConfig *config = new RclConfig(argcnf);
@ -53,10 +54,27 @@ RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int),
return 0;
}
// Retrieve the log file name and level
string logfilename, loglevel;
if (config->getConfParam(string("logfilename"), logfilename))
if (flags & RCLINIT_DAEMON) {
config->getConfParam(string("daemlogfilename"), logfilename);
config->getConfParam(string("daemloglevel"), loglevel);
}
if (logfilename.empty())
config->getConfParam(string("logfilename"), logfilename);
if (loglevel.empty())
config->getConfParam(string("loglevel"), loglevel);
// Initialize logging
if (!logfilename.empty()) {
logfilename = path_tildexpand(logfilename);
// If not an absolute path, compute relative to config dir
if (logfilename.at(0) != '/') {
logfilename = path_cat(config->getConfDir(), logfilename);
}
DebugLog::setfilename(logfilename.c_str());
if (config->getConfParam(string("loglevel"), loglevel)) {
}
if (!loglevel.empty()) {
int lev = atoi(loglevel.c_str());
DebugLog::getdbl()->setloglevel(lev);
}

View File

@ -16,14 +16,35 @@
*/
#ifndef _RCLINIT_H_INCLUDED_
#define _RCLINIT_H_INCLUDED_
/* @(#$Id: rclinit.h,v 1.4 2006-09-08 09:02:47 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: rclinit.h,v 1.5 2006-11-08 07:22:14 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#ifndef NO_NAMESPACES
using std::string;
#endif
class RclConfig;
extern RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int),
std::string &reason,
const std::string *argcnf = 0);
/**
* Initialize by reading configuration, opening log file, etc.
*
* @param flags misc modifiers
* @param cleanup function to call before exiting (atexit)
* @param sigcleanup function to call on terminal signal (INT/HUP...) This
* should typically set a flag which tells the program (recoll,
* recollindex etc.. to exit as soon as possible (after closing the db,
* etc.). cleanup will then be called by exit().
* @param reason in case of error: output string explaining things
* @param argcnf Configuration directory name from the command line (overriding
* default and environment
* @return the parsed configuration.
*/
enum RclInitFlags {RCLINIT_NONE=0, RCLINIT_DAEMON=1};
extern RclConfig *recollinit(RclInitFlags flags,
void (*cleanup)(void), void (*sigcleanup)(int),
string &reason, const string *argcnf = 0);
inline RclConfig *recollinit(void (*cleanup)(void), void (*sigcleanup)(int),
string &reason, const string *argcnf = 0) {
return recollinit(RCLINIT_NONE, cleanup, sigcleanup, reason, argcnf);
}
#endif /* _RCLINIT_H_INCLUDED_ */

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.26 2006-10-24 14:28:38 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.27 2006-11-08 07:22:14 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -285,7 +285,10 @@ int main(int argc, const char **argv)
Usage();
string reason;
RclConfig *config = recollinit(cleanup, sigcleanup, reason, &a_config);
RclInitFlags flags = (op_flags & OPT_m) && !(op_flags&OPT_D) ?
RCLINIT_DAEMON : RCLINIT_NONE;
RclConfig *config =
recollinit(flags, cleanup, sigcleanup, reason, &a_config);
if (config == 0 || !config->ok()) {
cerr << "Configuration problem: " << reason << endl;
exit(1);