34 "DBG_EXTRA_1",
"DBG_EXTRA_2",
"DBG_EXTRA_3",
"DBG_EXTRA_4"
67 std::string Logger::logDir_;
68 std::string Logger::logFile_;
120 screenVerbosityLevel_ = rememberscreenlevel_;
129 rememberscreenlevel_ = screenVerbosityLevel_;
147 int debug_level = 0, log_level = 0, bitmask = 0, verbose_level = 0;
148 if (strcmp(name,
"DEBUG_LEVEL") == 0)
157 screenVerbosityLevel_ = 0;
164 bitmask = *((
unsigned int *)sw->aux);
168 verbose_level |= bitmask;
171 verbose_level &= ~bitmask;
174 screenVerbosityLevel_ = verbose_level;
182 if (strcmp(name,
"LOGGING_LEVEL") == 0)
189 fileVerbosityLevel_ = 0;
198 bitmask = *((
unsigned int *)sw->aux);
202 fileVerbosityLevel_ |= bitmask;
205 fileVerbosityLevel_ &= ~bitmask;
214 if (!strcmp(name,
"LOG_OUTPUT"))
228 bool wasFileOff = configuration_ &
file_off;
233 configuration_ = configuration_ |
file_on;
235 configuration_ = configuration_ |
file_off;
238 configuration_ = configuration_ |
screen_on;
243 if (wasFileOff && (configuration_ &
file_on))
256 Logger *Logger::m_ =
nullptr;
258 #ifdef LOGGER_MULTITHREAD
259 pthread_mutex_t Logger::lock_ = PTHREAD_MUTEX_INITIALIZER;
260 inline void Logger::lock()
262 pthread_mutex_lock(&lock_);
265 inline void Logger::unlock()
267 pthread_mutex_unlock(&lock_);
273 void Logger::unlock()
278 Logger::Logger() : configured_(false)
280 gettimeofday(&initialTime_,
nullptr);
283 void Logger::configure(
const std::string &outputFile,
const loggerConf configuration,
const int fileVerbosityLevel,
284 const int screenVerbosityLevel)
288 fileVerbosityLevel_ = fileVerbosityLevel;
289 screenVerbosityLevel_ = screenVerbosityLevel;
290 rememberscreenlevel_ = screenVerbosityLevel_;
296 if (outputFile != logFile_)
298 char ts_date[32], ts_time[32];
304 strftime(ts_date,
sizeof(ts_date),
"%Y-%m-%d", tp);
305 strftime(ts_time,
sizeof(ts_time),
"%H:%M:%S", tp);
308 snprintf(dir,
MAXRBUF,
"%s/.indi/logs/%s/%s", getenv(
"HOME"), ts_date, outputFile.c_str());
312 snprintf(logFileBuf,
MAXRBUF,
"%s/%s_%s.log", dir, outputFile.c_str(), ts_time);
313 logFile_ = logFileBuf;
320 out_.open(logFile_.c_str(), std::ios::app);
323 configuration_ = configuration;
372 void Logger::print(
const char *devicename,
const unsigned int verbosityLevel,
const std::string &file,
const int line,
374 const char *message, ...)
377 if (verbosityLevel == 0)
382 bool filelog = (verbosityLevel & fileVerbosityLevel_) != 0;
383 bool screenlog = (verbosityLevel & screenVerbosityLevel_) != 0;
390 va_start(ap, message);
391 vsnprintf(msg, 257, message, ap);
397 std::cerr << msg << std::endl;
400 struct timeval currentTime, resTime;
402 gettimeofday(¤tTime,
nullptr);
403 timersub(¤tTime, &initialTime_, &resTime);
404 #if defined(__APPLE__)
405 snprintf(usec, 7,
"%06d", resTime.tv_usec);
407 snprintf(usec, 7,
"%06ld", resTime.tv_usec);
411 if ((configuration_ &
file_on) && filelog)
414 out_ <<
Tags[
rank(verbosityLevel)] <<
"\t" << (resTime.tv_sec) <<
"." << (usec) <<
" sec"
415 <<
"\t: " << msg << std::endl;
417 out_ <<
Tags[
rank(verbosityLevel)] <<
"\t" << (resTime.tv_sec) <<
"." << (usec) <<
" sec"
418 <<
"\t: [" << devicename <<
"] " << msg << std::endl;
421 if ((configuration_ &
screen_on) && screenlog)
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
void IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
ISwitch * IUFindOnSwitch(const ISwitchVectorProperty *svp)
Returns the first ON switch it finds in the vector switch property.
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
void IDMessage(const char *dev, const char *fmt,...)
#define DEBUGFDEVICE(device, priority, msg,...)
Namespace to encapsulate INDI client, drivers, and mediator classes.
int mkpath(std::string s, mode_t mode)
The Logger class is a simple logger to log messages to file and INDI clients. This is the implementat...
static ISwitch DebugLevelS[nlevels]
static ISwitch LoggingLevelS[nlevels]
static unsigned int customLevel
static unsigned int rank(unsigned int l)
Method used to print message called by the DEBUG() macro.
static const loggerConf screen_on
static struct switchinit DebugLevelSInit[nlevels]
static const loggerConf file_off
static ISwitchVectorProperty DebugLevelSP
static const unsigned int nlevels
static bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
void configure(const std::string &outputFile, const loggerConf configuration, const int fileVerbosityLevel, const int screenVerbosityLevel)
Method to configure the logger. Called by the DEBUG_CONF() macro. To make implementation easier,...
static ISwitchVectorProperty LoggingLevelSP
void print(const char *devicename, const unsigned int verbosityLevel, const std::string &sourceFile, const int codeLine, const char *message,...)
static Logger & getInstance()
Method to get a reference to the object (i.e., Singleton) It is a static method.
static bool initProperties(INDI::DefaultDevice *device)
static bool updateProperties(bool enable)
static bool saveConfigItems(FILE *fp)
static struct switchinit LoggingLevelSInit[nlevels]
static const loggerConf file_on
static ISwitch ConfigurationS[2]
int addDebugLevel(const char *debugLevelName, const char *LoggingLevelName)
Adds a new debugging level to the driver.
static char Tags[nlevels][MAXINDINAME]
static const unsigned int defaultlevel
static const loggerConf screen_off
static unsigned int nDevices
static ISwitchVectorProperty ConfigurationSP
Switch vector property descriptor.