whitespace

This commit is contained in:
Isaac Connor 2018-03-22 10:25:56 -04:00
parent b220b8f588
commit ccf0336c9d
1 changed files with 56 additions and 56 deletions

View File

@ -61,22 +61,22 @@ void Logger::usrHandler( int sig ) {
logger->level( logger->level()+1 );
else if ( sig == SIGUSR2 )
logger->level( logger->level()-1 );
Info( "Logger - Level changed to %d", logger->level() );
Info("Logger - Level changed to %d", logger->level());
}
Logger::Logger() :
mLevel( INFO ),
mTerminalLevel( NOLOG ),
mDatabaseLevel( NOLOG ),
mFileLevel( NOLOG ),
mSyslogLevel( NOLOG ),
mEffectiveLevel( NOLOG ),
mLevel(INFO),
mTerminalLevel(NOLOG),
mDatabaseLevel(NOLOG),
mFileLevel(NOLOG),
mSyslogLevel(NOLOG),
mEffectiveLevel(NOLOG),
//mLogPath( staticConfig.PATH_LOGS.c_str() ),
//mLogFile( mLogPath+"/"+mId+".log" ),
mDbConnected( false ),
mLogFileFP( NULL ),
mHasTerminal( false ),
mFlush( false ) {
mDbConnected(false),
mLogFileFP(NULL),
mHasTerminal(false),
mFlush(false) {
if ( smInstance ) {
Panic( "Attempt to create second instance of Logger class" );
@ -124,7 +124,7 @@ Logger::~Logger() {
#endif
}
void Logger::initialise( const std::string &id, const Options &options ) {
void Logger::initialise(const std::string &id, const Options &options) {
char *envPtr;
if ( !id.empty() )
@ -132,7 +132,7 @@ void Logger::initialise( const std::string &id, const Options &options ) {
std::string tempLogFile;
if ( (envPtr = getTargettedEnv( "LOG_FILE" )) )
if ( (envPtr = getTargettedEnv("LOG_FILE")) )
tempLogFile = envPtr;
else if ( options.mLogFile.size() )
tempLogFile = options.mLogFile;
@ -171,20 +171,20 @@ void Logger::initialise( const std::string &id, const Options &options ) {
if ( (envPtr = getenv( "LOG_PRINT" )) )
tempTerminalLevel = atoi(envPtr) ? DEBUG9 : NOLOG;
if ( (envPtr = getTargettedEnv( "LOG_LEVEL" )) )
if ( (envPtr = getTargettedEnv("LOG_LEVEL")) )
tempLevel = atoi(envPtr);
if ( (envPtr = getTargettedEnv( "LOG_LEVEL_TERM" )) )
if ( (envPtr = getTargettedEnv("LOG_LEVEL_TERM")) )
tempTerminalLevel = atoi(envPtr);
if ( (envPtr = getTargettedEnv( "LOG_LEVEL_DATABASE" )) )
if ( (envPtr = getTargettedEnv("LOG_LEVEL_DATABASE")) )
tempDatabaseLevel = atoi(envPtr);
if ( (envPtr = getTargettedEnv( "LOG_LEVEL_FILE" )) )
if ( (envPtr = getTargettedEnv("LOG_LEVEL_FILE")) )
tempFileLevel = atoi(envPtr);
if ( (envPtr = getTargettedEnv( "LOG_LEVEL_SYSLOG" )) )
if ( (envPtr = getTargettedEnv("LOG_LEVEL_SYSLOG")) )
tempSyslogLevel = atoi(envPtr);
if ( config.log_debug ) {
StringVector targets = split( config.log_debug_target, "|" );
StringVector targets = split(config.log_debug_target, "|");
for ( unsigned int i = 0; i < targets.size(); i++ ) {
const std::string &target = targets[i];
if ( target == mId || target == "_"+mId || target == "_"+mIdRoot || target == "" ) {
@ -206,15 +206,14 @@ void Logger::initialise( const std::string &id, const Options &options ) {
if ( tempLevel > INFO ) tempLevel = INFO;
} // end if config.log_debug
logFile(tempLogFile);
logFile( tempLogFile );
terminalLevel(tempTerminalLevel);
databaseLevel(tempDatabaseLevel);
fileLevel(tempFileLevel);
syslogLevel(tempSyslogLevel);
terminalLevel( tempTerminalLevel );
databaseLevel( tempDatabaseLevel );
fileLevel( tempFileLevel );
syslogLevel( tempSyslogLevel );
level( tempLevel );
level(tempLevel);
mFlush = false;
if ( (envPtr = getenv("LOG_FLUSH")) ) {
@ -223,24 +222,24 @@ void Logger::initialise( const std::string &id, const Options &options ) {
mFlush = true;
}
//mRuntime = (envPtr = getenv( "LOG_RUNTIME")) ? atoi( envPtr ) : false;
{
struct sigaction action;
memset( &action, 0, sizeof(action) );
memset(&action, 0, sizeof(action));
action.sa_handler = usrHandler;
action.sa_flags = SA_RESTART;
if ( sigaction( SIGUSR1, &action, 0 ) < 0 ) {
Fatal( "sigaction(), error = %s", strerror(errno) );
// Does this REALLY need to be fatal?
if ( sigaction(SIGUSR1, &action, 0) < 0 ) {
Fatal("sigaction(), error = %s", strerror(errno));
}
if ( sigaction( SIGUSR2, &action, 0 ) < 0) {
Fatal( "sigaction(), error = %s", strerror(errno) );
if ( sigaction(SIGUSR2, &action, 0) < 0) {
Fatal("sigaction(), error = %s", strerror(errno));
}
}
mInitialised = true;
Debug( 1, "LogOpts: level=%s/%s, screen=%s, database=%s, logfile=%s->%s, syslog=%s",
Debug(1, "LogOpts: level=%s/%s, screen=%s, database=%s, logfile=%s->%s, syslog=%s",
smCodes[mLevel].c_str(),
smCodes[mEffectiveLevel].c_str(),
smCodes[mTerminalLevel].c_str(),
@ -252,7 +251,7 @@ void Logger::initialise( const std::string &id, const Options &options ) {
}
void Logger::terminate() {
Debug(1, "Terminating Logger" );
Debug(1, "Terminating Logger");
if ( mFileLevel > NOLOG )
closeFile();
@ -264,60 +263,61 @@ void Logger::terminate() {
closeDatabase();
}
bool Logger::boolEnv( const std::string &name, bool defaultValue ) {
const char *envPtr = getenv( name.c_str() );
return( envPtr ? atoi( envPtr ) : defaultValue );
// These don't belong here, they have nothing to do with logging
bool Logger::boolEnv(const std::string &name, bool defaultValue) {
const char *envPtr = getenv(name.c_str());
return envPtr ? atoi(envPtr) : defaultValue;
}
int Logger::intEnv( const std::string &name, bool defaultValue ) {
const char *envPtr = getenv( name.c_str() );
return( envPtr ? atoi( envPtr ) : defaultValue );
int Logger::intEnv(const std::string &name, bool defaultValue) {
const char *envPtr = getenv(name.c_str());
return envPtr ? atoi(envPtr) : defaultValue;
}
std::string Logger::strEnv( const std::string &name, const std::string &defaultValue ) {
const char *envPtr = getenv( name.c_str() );
return( envPtr ? envPtr : defaultValue );
std::string Logger::strEnv(const std::string &name, const std::string &defaultValue) {
const char *envPtr = getenv(name.c_str());
return envPtr ? envPtr : defaultValue;
}
char *Logger::getTargettedEnv( const std::string &name ) {
char *Logger::getTargettedEnv(const std::string &name) {
std::string envName;
envName = name+"_"+mId;
char *envPtr = getenv( envName.c_str() );
char *envPtr = getenv(envName.c_str());
if ( !envPtr && mId != mIdRoot ) {
envName = name+"_"+mIdRoot;
envPtr = getenv( envName.c_str() );
envPtr = getenv(envName.c_str());
}
if ( !envPtr )
envPtr = getenv( name.c_str() );
return( envPtr );
envPtr = getenv(name.c_str());
return envPtr;
}
const std::string &Logger::id( const std::string &id ) {
const std::string &Logger::id(const std::string &id) {
std::string tempId = id;
size_t pos;
// Remove whitespace
while ( (pos = tempId.find_first_of( " \t" )) != std::string::npos ) {
tempId.replace( pos, 1, "" );
tempId.replace(pos, 1, "");
}
// Replace non-alphanum with underscore
while ( (pos = tempId.find_first_not_of( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" )) != std::string::npos ) {
tempId.replace( pos, 1, "_" );
while ( (pos = tempId.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) != std::string::npos ) {
tempId.replace(pos, 1, "_");
}
if ( mId != tempId ) {
mId = tempId;
pos = mId.find( '_' );
pos = mId.find('_');
if ( pos != std::string::npos ) {
mIdRoot = mId.substr( 0, pos );
mIdRoot = mId.substr(0, pos);
if ( ++pos < mId.size() )
mIdArgs = mId.substr( pos );
mIdArgs = mId.substr(pos);
}
}
return( mId );
}
Logger::Level Logger::level( Logger::Level level ) {
Logger::Level Logger::level(Logger::Level level) {
if ( level > NOOPT ) {
level = limit(level);
if ( mLevel != level )