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