Skip to content

Commit

Permalink
Changes following review
Browse files Browse the repository at this point in the history
Signed-off-by: Shamser Ahmed <shamser.ahmed@lexisnexis.com>
  • Loading branch information
shamser committed Oct 1, 2024
1 parent 7e0a205 commit 56045a7
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 63 deletions.
88 changes: 51 additions & 37 deletions dali/base/sysinfologger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define ATTR_HIDDEN "@hidden"
#define ATTR_SOURCE "@source"

static void extractDate(unsigned __int64 ts, unsigned & year, unsigned & month, unsigned & day)
static void extractDate(timestamp_type ts, unsigned & year, unsigned & month, unsigned & day)
{
CDateTime timeStamp;
timeStamp.setTimeStamp(ts);
Expand Down Expand Up @@ -77,7 +77,7 @@ class CSysInfoLoggerMsg : implements ISysInfoLoggerMsg
{
msgPtree.setown(createPTree(MSG_NODE));
}
CSysInfoLoggerMsg(unsigned id, const LogMsgCategory & cat, LogMsgCode code, const char * source, const char * msg, unsigned __int64 ts, bool hidden)
CSysInfoLoggerMsg(unsigned id, const LogMsgCategory & cat, LogMsgCode code, const char * source, const char * msg, timestamp_type ts, bool hidden)
{
msgPtree.setown(createPTree(MSG_NODE));
msgPtree->setPropInt64(ATTR_ID, id);
Expand All @@ -99,7 +99,7 @@ class CSysInfoLoggerMsg : implements ISysInfoLoggerMsg
{
return msgPtree->getPropBool(ATTR_HIDDEN, false);
}
virtual unsigned __int64 queryTimeStamp() const override
virtual timestamp_type queryTimeStamp() const override
{
return msgPtree->getPropInt64(ATTR_TIMESTAMP);
}
Expand Down Expand Up @@ -161,7 +161,7 @@ class CSysInfoLoggerMsgFilter : public CSimpleInterfaceOf<ISysInfoLoggerMsgFilte
// (For numeric fields: match only if it has a non-zero value)
bool hiddenOnly = false;
bool visibleOnly = false;
unsigned __int64 matchTimeStamp = 0;
timestamp_type matchTimeStamp = 0;
StringAttr matchSource; // only matchSource when not empty
LogMsgCode matchCode = 0;
LogMsgAudience matchAudience = MSGAUD_all;
Expand All @@ -176,17 +176,15 @@ class CSysInfoLoggerMsgFilter : public CSimpleInterfaceOf<ISysInfoLoggerMsgFilte
unsigned matchId = 0;

public:
CSysInfoLoggerMsgFilter()
CSysInfoLoggerMsgFilter(const char *_source): matchSource(_source)
{
}
CSysInfoLoggerMsgFilter(unsigned __int64 msgId)
CSysInfoLoggerMsgFilter(unsigned __int64 msgId, const char *_source): matchSource(_source)
{
setMatchMsgId(msgId);
}
CSysInfoLoggerMsgFilter(bool _visibleOnly, bool _hiddenOnly, unsigned _year, unsigned _month, unsigned _day) :
visibleOnly(_visibleOnly), hiddenOnly(_hiddenOnly),
matchEndYear(_year), matchEndMonth(_month), matchEndDay(_day),
matchStartYear(_year), matchStartMonth(_month), matchStartDay(_day)
CSysInfoLoggerMsgFilter(bool _visibleOnly, bool _hiddenOnly, unsigned _year, unsigned _month, unsigned _day, const char *_source) :
visibleOnly(_visibleOnly), hiddenOnly(_hiddenOnly), matchSource(_source)
{
if (hiddenOnly && visibleOnly)
throw makeStringException(-1, "ISysInfoLoggerMsgFilter: cannot filter by both hiddenOnly and visibleOnly");
Expand All @@ -200,7 +198,7 @@ class CSysInfoLoggerMsgFilter : public CSimpleInterfaceOf<ISysInfoLoggerMsgFilte
{
visibleOnly = true;
}
virtual void setMatchTimeStamp(unsigned __int64 ts) override
virtual void setMatchTimeStamp(timestamp_type ts) override
{
matchTimeStamp = ts;
}
Expand Down Expand Up @@ -269,7 +267,7 @@ class CSysInfoLoggerMsgFilter : public CSimpleInterfaceOf<ISysInfoLoggerMsgFilte
{
return haveDateRange;
}
virtual bool isInDateRange(unsigned __int64 ts) const override
virtual bool isInDateRange(timestamp_type ts) const override
{
unsigned tyear, tmonth, tday;
extractDate(ts, tyear, tmonth, tday);
Expand Down Expand Up @@ -320,7 +318,7 @@ class CSysInfoLoggerMsgFilter : public CSimpleInterfaceOf<ISysInfoLoggerMsgFilte
{
return visibleOnly;
}
virtual unsigned __int64 queryMatchTimeStamp() const override
virtual timestamp_type queryMatchTimeStamp() const override
{
return matchTimeStamp;
}
Expand Down Expand Up @@ -371,6 +369,7 @@ class CSysInfoLoggerMsgFilter : public CSimpleInterfaceOf<ISysInfoLoggerMsgFilte
bool hardMatchMonth = matchStartMonth && (matchStartMonth==matchEndMonth);
if (hardMatchYear && hardMatchMonth)
{
// future: optimize when month unknown with "m%04u*"
xpath.appendf("m%04u%02u", matchStartYear, matchStartMonth);
if (matchStartDay==matchEndDay)
{
Expand Down Expand Up @@ -402,19 +401,21 @@ class CSysInfoLoggerMsgFilter : public CSimpleInterfaceOf<ISysInfoLoggerMsgFilte
}
};

ISysInfoLoggerMsgFilter * createSysInfoLoggerMsgFilter()
ISysInfoLoggerMsgFilter * createSysInfoLoggerMsgFilter(const char *source)
{
return new CSysInfoLoggerMsgFilter();
return new CSysInfoLoggerMsgFilter(source);
}

ISysInfoLoggerMsgFilter * createSysInfoLoggerMsgFilter(unsigned __int64 msgId)
ISysInfoLoggerMsgFilter * createSysInfoLoggerMsgFilter(unsigned __int64 msgId, const char *source)
{
return new CSysInfoLoggerMsgFilter(msgId);
return new CSysInfoLoggerMsgFilter(msgId, source);
}

class CSysInfoLoggerMsgIterator : public CSimpleInterfaceOf<ISysInfoLoggerMsgIterator>
{
Linked<IConstSysInfoLoggerMsgFilter> filter;
// N.b. IRemoteConnection exists for the duration of the iterator so if this iterator exists for too long, it could cause
// performance issues for other clients: consider caching some messages and releasing connection (and reopening as necessary).
Owned<IRemoteConnection> conn;
bool updateable = false;
Owned<IPropertyTreeIterator> msgIter;
Expand All @@ -426,7 +427,7 @@ class CSysInfoLoggerMsgIterator : public CSimpleInterfaceOf<ISysInfoLoggerMsgIte
{
for (; msgIter->isValid(); msgIter->next())
{
unsigned __int64 ts = msgIter->query().getPropInt64(ATTR_TIMESTAMP, 0);
timestamp_type ts = msgIter->query().getPropInt64(ATTR_TIMESTAMP, 0);
if (filter->isInDateRange(ts))
return true;
}
Expand Down Expand Up @@ -476,9 +477,9 @@ class CSysInfoLoggerMsgIterator : public CSimpleInterfaceOf<ISysInfoLoggerMsgIte
}
};

ISysInfoLoggerMsgIterator * createSysInfoLoggerMsgIterator(bool visibleOnly, bool hiddenOnly, unsigned year, unsigned month, unsigned day)
ISysInfoLoggerMsgIterator * createSysInfoLoggerMsgIterator(bool visibleOnly, bool hiddenOnly, unsigned year, unsigned month, unsigned day, const char *source)
{
Owned<CSysInfoLoggerMsgFilter> filter = new CSysInfoLoggerMsgFilter(visibleOnly, hiddenOnly, year, month, day);
Owned<CSysInfoLoggerMsgFilter> filter = new CSysInfoLoggerMsgFilter(visibleOnly, hiddenOnly, year, month, day, source);
return new CSysInfoLoggerMsgIterator(filter, false);
}

Expand All @@ -488,7 +489,7 @@ ISysInfoLoggerMsgIterator * createSysInfoLoggerMsgIterator(IConstSysInfoLoggerMs
}

// returns messageId
unsigned __int64 logSysInfoError(const LogMsgCategory & cat, LogMsgCode code, const char *source, const char * msg, unsigned __int64 ts)
unsigned __int64 logSysInfoError(const LogMsgCategory & cat, LogMsgCode code, const char *source, const char * msg, timestamp_type ts)
{
if (ts==0)
ts = getTimeStampNowValue();
Expand Down Expand Up @@ -533,9 +534,9 @@ unsigned updateMessage(IConstSysInfoLoggerMsgFilter * msgFilter, std::function<v
return count;
}

unsigned updateMessage(unsigned __int64 msgId, std::function<void (CSysInfoLoggerMsg &)> updateOp)
unsigned updateMessage(unsigned __int64 msgId, const char *source, std::function<void (CSysInfoLoggerMsg &)> updateOp)
{
Owned<IConstSysInfoLoggerMsgFilter> msgFilter = createSysInfoLoggerMsgFilter(msgId);
Owned<IConstSysInfoLoggerMsgFilter> msgFilter = createSysInfoLoggerMsgFilter(msgId, source);
return updateMessage(msgFilter, updateOp);
}

Expand All @@ -544,19 +545,19 @@ unsigned hideLogSysInfoMsg(IConstSysInfoLoggerMsgFilter * msgFilter)
return updateMessage(msgFilter, [](CSysInfoLoggerMsg & sysInfoMsg){sysInfoMsg.setHidden(true);});
}

bool hideLogSysInfoMsg(unsigned __int64 msgId)
bool hideLogSysInfoMsg(unsigned __int64 msgId, const char *source)
{
return updateMessage(msgId, [](CSysInfoLoggerMsg & sysInfoMsg){sysInfoMsg.setHidden(true);})==1;
return updateMessage(msgId, source, [](CSysInfoLoggerMsg & sysInfoMsg){sysInfoMsg.setHidden(true);})==1;
}

unsigned unhideLogSysInfoMsg(IConstSysInfoLoggerMsgFilter * msgFilter)
{
return updateMessage(msgFilter, [](CSysInfoLoggerMsg & sysInfoMsg){sysInfoMsg.setHidden(false);});
}

bool unhideLogSysInfoMsg(unsigned __int64 msgId)
bool unhideLogSysInfoMsg(unsigned __int64 msgId, const char *source)
{
return updateMessage(msgId, [](CSysInfoLoggerMsg & sysInfoMsg){sysInfoMsg.setHidden(false);})==1;
return updateMessage(msgId, source, [](CSysInfoLoggerMsg & sysInfoMsg){sysInfoMsg.setHidden(false);})==1;
}

unsigned deleteLogSysInfoMsg(IConstSysInfoLoggerMsgFilter * msgFilter)
Expand All @@ -577,20 +578,19 @@ unsigned deleteLogSysInfoMsg(IConstSysInfoLoggerMsgFilter * msgFilter)
unsigned count = 0;
for (auto & xpath: deleteXpathList)
{
if (root->removeProp(xpath.c_str()));
if (root->removeProp(xpath.c_str()))
++count;
}
return count;
}

bool deleteLogSysInfoMsg(unsigned __int64 msgId)
bool deleteLogSysInfoMsg(unsigned __int64 msgId, const char *source)
{
Owned<ISysInfoLoggerMsgFilter> msgFilter = createSysInfoLoggerMsgFilter();
msgFilter->setMatchMsgId(msgId);
Owned<ISysInfoLoggerMsgFilter> msgFilter = createSysInfoLoggerMsgFilter(msgId, source);
return deleteLogSysInfoMsg(msgFilter);
}

unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigned year, unsigned month, unsigned day)
unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigned year, unsigned month, unsigned day, const char *source)
{
if (!year && month)
throw makeStringExceptionV(-1, "deleteOlderThanLogSysInfoMsg: year must be provided if month is specified (year=%u, month=%u, day=%u)", year, month, day);
Expand All @@ -601,14 +601,16 @@ unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigne
if (day>31)
throw makeStringExceptionV(-1, "deleteOlderThanLogSysInfoMsg: invalid day(year=%u, month=%u, day=%u)", year, month, day);
// With visibleOnly/hiddenOnly option, use createSysInfoLoggerMsgFilter()
if (visibleOnly || hiddenOnly)
if (visibleOnly || hiddenOnly || day)
{
unsigned count = 0;
Owned<ISysInfoLoggerMsgFilter> msgFilter = createSysInfoLoggerMsgFilter();
Owned<ISysInfoLoggerMsgFilter> msgFilter = createSysInfoLoggerMsgFilter(source);
if (hiddenOnly)
msgFilter->setHiddenOnly();
if (visibleOnly)
msgFilter->setVisibleOnly();
if (source)
msgFilter->setMatchSource(source);
msgFilter->setOlderThanDate(year, month, day);
return deleteLogSysInfoMsg(msgFilter);
}
Expand All @@ -620,7 +622,9 @@ unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigne

std::vector<std::string> deleteXpathList;
IPropertyTree * root = conn->queryRoot();
// future: optimize by getting only minimum set of subtrees to delete and get sorted elements(so search can stop earlier)
Owned<IPropertyTreeIterator> monthIter = root->getElements("*");
Owned<IException> innerException; //only first exception record/reported
ForEach(*monthIter)
{
IPropertyTree & monthPT = monthIter->query();
Expand All @@ -636,7 +640,11 @@ unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigne
msgMonth = readDigits(p, 2, false);
}
if (msgYear == 0 || msgMonth == 0)
throw makeStringExceptionV(-1, "child of " SYS_INFO_ROOT " is invalid: %s", monthPT.queryName());
{
if (!innerException)
innerException.setown(makeStringExceptionV(-1, "child of " SYS_INFO_ROOT " is invalid: %s", monthPT.queryName()));
continue;
}
if (msgYear > year)
continue;
if (msgYear < year)
Expand All @@ -659,7 +667,11 @@ unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigne
if (*d++ == 'd')
msgDay = readDigits(d, 2);
if (msgDay == 0)
throw makeStringExceptionV(-1, "child of " SYS_INFO_ROOT "/%s is invalid: %s", monthPT.queryName(), dayPT.queryName());
{
if (!innerException)
innerException.setown(makeStringExceptionV(-1, "child of " SYS_INFO_ROOT "/%s is invalid: %s", monthPT.queryName(), dayPT.queryName()));
continue;
}
if (day && (msgDay >= day))
continue;

Expand All @@ -670,13 +682,15 @@ unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigne
}
}
}

unsigned count = 0;
for (auto & xpath: deleteXpathList)
{
if (root->removeProp(xpath.c_str()));
++count;
}

if (innerException) // allow items to be deleted even if there is an exception
throw innerException.getClear();

return count;
}
24 changes: 12 additions & 12 deletions dali/base/sysinfologger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
interface ISysInfoLoggerMsg
{
virtual bool queryIsHidden() const = 0;
virtual unsigned __int64 queryTimeStamp() const = 0;
virtual timestamp_type queryTimeStamp() const = 0;
virtual const char * querySource() const = 0;
virtual LogMsgCode queryLogMsgCode() const = 0;
virtual LogMsgAudience queryAudience() const = 0;
Expand All @@ -42,10 +42,10 @@ interface ISysInfoLoggerMsg
interface IConstSysInfoLoggerMsgFilter : public IInterface
{
virtual bool hasDateRange() const = 0;
virtual bool isInDateRange(unsigned __int64 ts) const = 0;
virtual bool isInDateRange(timestamp_type ts) const = 0;
virtual bool queryHiddenOnly() const = 0;
virtual bool queryVisibleOnly() const = 0;
virtual unsigned __int64 queryMatchTimeStamp() const = 0;
virtual timestamp_type queryMatchTimeStamp() const = 0;
virtual unsigned queryStartYear() const = 0;
virtual unsigned queryStartMonth() const = 0;
virtual unsigned queryStartDay() const = 0;
Expand All @@ -63,7 +63,7 @@ interface ISysInfoLoggerMsgFilter : extends IConstSysInfoLoggerMsgFilter
{
virtual void setHiddenOnly() = 0;
virtual void setVisibleOnly() = 0;
virtual void setMatchTimeStamp(unsigned __int64 ts) = 0;
virtual void setMatchTimeStamp(timestamp_type ts) = 0;
virtual void setMatchSource(const char * source) = 0;
virtual void setMatchCode(LogMsgCode code) = 0;
virtual void setMatchAudience(LogMsgAudience audience) = 0;
Expand All @@ -75,18 +75,18 @@ interface ISysInfoLoggerMsgFilter : extends IConstSysInfoLoggerMsgFilter

typedef IIteratorOf<ISysInfoLoggerMsg> ISysInfoLoggerMsgIterator;

SYSINFO_API ISysInfoLoggerMsgFilter * createSysInfoLoggerMsgFilter();
SYSINFO_API ISysInfoLoggerMsgFilter * createSysInfoLoggerMsgFilter(unsigned __int64 msgId);
SYSINFO_API ISysInfoLoggerMsgIterator * createSysInfoLoggerMsgIterator(bool _visibleOnly, bool _hiddenOnly, unsigned _year, unsigned _month, unsigned _day);
SYSINFO_API ISysInfoLoggerMsgFilter * createSysInfoLoggerMsgFilter(const char *source=nullptr);
SYSINFO_API ISysInfoLoggerMsgFilter * createSysInfoLoggerMsgFilter(unsigned __int64 msgId, const char *source=nullptr);
SYSINFO_API ISysInfoLoggerMsgIterator * createSysInfoLoggerMsgIterator(bool _visibleOnly, bool _hiddenOnly, unsigned _year, unsigned _month, unsigned _day, const char *source=nullptr);
SYSINFO_API ISysInfoLoggerMsgIterator * createSysInfoLoggerMsgIterator(ISysInfoLoggerMsgFilter * msgFilter);

SYSINFO_API unsigned __int64 logSysInfoError(const LogMsgCategory & cat, LogMsgCode code, const char *source, const char * msg, unsigned __int64 ts);
SYSINFO_API unsigned hideLogSysInfoMsg(IConstSysInfoLoggerMsgFilter * msgFilter);
SYSINFO_API bool hideLogSysInfoMsg(unsigned __int64 msgId);
SYSINFO_API unsigned unhideLogSysInfoMsg(IConstSysInfoLoggerMsgFilter * msgFilter);
SYSINFO_API bool unhideLogSysInfoMsg(unsigned __int64 msgId);
SYSINFO_API bool hideLogSysInfoMsg(unsigned __int64 msgId, const char *source=nullptr);
SYSINFO_API unsigned unhideLogSysInfoMsg(IConstSysInfoLoggerMsgFilter * msgFilter, const char *source=nullptr);
SYSINFO_API bool unhideLogSysInfoMsg(unsigned __int64 msgId, const char *source=nullptr);
SYSINFO_API unsigned deleteLogSysInfoMsg(IConstSysInfoLoggerMsgFilter * msgFilter);
SYSINFO_API bool deleteLogSysInfoMsg(unsigned __int64 msgId);
SYSINFO_API unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigned year, unsigned month, unsigned day);
SYSINFO_API bool deleteLogSysInfoMsg(unsigned __int64 msgId, const char *source=nullptr);
SYSINFO_API unsigned deleteOlderThanLogSysInfoMsg(bool visibleOnly, bool hiddenOnly, unsigned year, unsigned month, unsigned day, const char *source=nullptr);

#endif
Loading

0 comments on commit 56045a7

Please sign in to comment.