Prechádzať zdrojové kódy

HPCC-16648 Add methods to log interface to retrieve current log position

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 8 rokov pred
rodič
commit
dac41fe714

+ 1 - 0
system/jlib/jdebug.cpp

@@ -3756,6 +3756,7 @@ public:
     virtual char const *disable() { return 0; }
     virtual void enable() {}
     virtual bool getLogName(StringBuffer &name __attribute__((unused))) const { return false; }
+    virtual offset_t getLogPosition(StringBuffer &logFileName __attribute__((unused))) const { return 0; };
 
     // interface IUserMetric
     virtual unsigned __int64 queryCount() const { return counter; }

+ 8 - 0
system/jlib/jlog.cpp

@@ -1634,6 +1634,14 @@ void CLogMsgManager::panic(char const * reason) const
     fprintf(stderr, "%s", reason); // not sure there's anything more useful we can do here
 }
 
+offset_t CLogMsgManager::getLogPosition(StringBuffer &logFileName, const ILogMsgHandler * handler) const
+{
+    if (processor)
+        processor->flush(10*1000);
+    WriteLockBlock block(monitorLock);  // Prevents any incoming messages as we are doing this
+    return handler->getLogPosition(logFileName);
+}
+
 aindex_t CLogMsgManager::find(const ILogMsgHandler * handler) const
 {
     // N.B. Should be used inside critical block

+ 2 - 0
system/jlib/jlog.hpp

@@ -501,6 +501,7 @@ interface jlib_decl ILogMsgHandler : public IInterface
     virtual char const *      disable() { return 0; }
     virtual void              enable() {}
     virtual bool              getLogName(StringBuffer &name) const = 0;
+    virtual offset_t          getLogPosition(StringBuffer &logFileName) const = 0;
 };
 
 // Class on manager's list of children which sends new filters to children, and holds thread which receives log messages
@@ -578,6 +579,7 @@ interface jlib_decl ILogMsgManager : public ILogMsgListener
     virtual void              report(const LogMsg & msg) const = 0;
     virtual LogMsgId          getNextID() = 0;
     virtual bool              rejectsCategory(const LogMsgCategory & cat) const = 0;
+    virtual offset_t          getLogPosition(StringBuffer &logFileName, const ILogMsgHandler * handler) const = 0;
 };
 
 // CONCRETE CLASSES

+ 6 - 0
system/jlib/jlog.ipp

@@ -505,6 +505,7 @@ public:
     char const *              disable() { crit.enter(); return "HANDLER"; }
     void                      enable() { crit.leave(); }
     bool                      getLogName(StringBuffer &name) const { return false; }
+    offset_t                  getLogPosition(StringBuffer &name) const { return 0; }
 protected:
     FILE *                    handle;
     unsigned                  messageFields;
@@ -548,6 +549,7 @@ public:
     char const *              disable();
     void                      enable();
     bool                      getLogName(StringBuffer &name) const { name.append(filename); return true; }
+    offset_t                  getLogPosition(StringBuffer &name) const { CriticalBlock block(crit); fflush(handle); name.append(filename); return ftell(handle); }
                 
 protected:
     FILE *                    handle;
@@ -605,6 +607,7 @@ public:
     char const *              disable();
     void                      enable();
     bool                      getLogName(StringBuffer &name) const { CriticalBlock block(crit); name.append(filename); return true; }
+    offset_t                  getLogPosition(StringBuffer &name) const { CriticalBlock block(crit); fflush(handle); name.append(filename); return ftell(handle); }
 protected:
     void                      checkRollover() const;
     void                      doRollover(bool daily, const char *forceName = NULL) const;
@@ -639,6 +642,7 @@ public:
     char const *              disable();
     void                      enable();
     bool                      getLogName(StringBuffer &name) const { name.append(filename); return true; }
+    offset_t                  getLogPosition(StringBuffer &name) const { CriticalBlock block(crit); name.append(filename); return fstr->tell(); }
 protected:
     StringAttr                filename;
     bool                      append;
@@ -667,6 +671,7 @@ public:
     char const *              disable() { return "Audit"; }
     void                      enable() {}
     bool                      getLogName(StringBuffer &name) const { return false; }
+    offset_t                  getLogPosition(StringBuffer &logFileName) const { return 0; }
 protected:
     ISysLogEventLogger *      logger;
     unsigned                  fields;
@@ -782,6 +787,7 @@ public:
     void                      setSession(LogMsgSessionId _session) { session = _session; }
     LogMsgSessionId           querySession() const { return session; }
     bool                      rejectsCategory(const LogMsgCategory & cat) const;
+    virtual offset_t          getLogPosition(StringBuffer &logFileName, const ILogMsgHandler * handler) const;
 
 private:
     void                      sendFilterToChildren(bool locked = false) const;

+ 1 - 0
system/mp/mplog.ipp

@@ -151,6 +151,7 @@ public:
     bool                      queryConnected() const { return connected; }
     void                      markDisconnected() { connected = false; }
     bool                      getLogName(StringBuffer &name) const { return false; }
+    offset_t                  getLogPosition(StringBuffer &name) const { return 0; }
 private:
     Linked<INode>             parentNode;
     MPLogId                   cid;