forked from Github/Axter-Stash
Added LogOnce function
This commit is contained in:
@@ -215,9 +215,10 @@ class StashPluginHelper:
|
|||||||
if (printTo & self.LOG_TO_STDERR) and (logLevel != logging.DEBUG or self.DEBUG_TRACING or logAlways):
|
if (printTo & self.LOG_TO_STDERR) and (logLevel != logging.DEBUG or self.DEBUG_TRACING or logAlways):
|
||||||
print(f"StdErr: {LN_Str} {levelStr}{logMsg}", file=sys.stderr)
|
print(f"StdErr: {LN_Str} {levelStr}{logMsg}", file=sys.stderr)
|
||||||
|
|
||||||
def Trace(self, logMsg = "", printTo = 0, logAlways = False):
|
def Trace(self, logMsg = "", printTo = 0, logAlways = False, lineNo = -1):
|
||||||
if printTo == 0: printTo = self.LOG_TO_FILE
|
if printTo == 0: printTo = self.LOG_TO_FILE
|
||||||
lineNo = inspect.currentframe().f_back.f_lineno
|
if lineNo == -1:
|
||||||
|
lineNo = lineNo = inspect.currentframe().f_back.f_lineno
|
||||||
logLev = logging.INFO if logAlways else logging.DEBUG
|
logLev = logging.INFO if logAlways else logging.DEBUG
|
||||||
if self.DEBUG_TRACING or logAlways:
|
if self.DEBUG_TRACING or logAlways:
|
||||||
if logMsg == "":
|
if logMsg == "":
|
||||||
@@ -236,7 +237,19 @@ class StashPluginHelper:
|
|||||||
self.traceOncePreviousHits.append(FuncAndLineNo)
|
self.traceOncePreviousHits.append(FuncAndLineNo)
|
||||||
if logMsg == "":
|
if logMsg == "":
|
||||||
logMsg = f"Line number {lineNo}..."
|
logMsg = f"Line number {lineNo}..."
|
||||||
self.Log(logMsg, printTo, logLev, lineNo, self.LEV_TRACE, logAlways)
|
self.Log(logMsg, printTo, logLev, lineNo)
|
||||||
|
|
||||||
|
# Log INFO on first call, then do Trace on remaining calls.
|
||||||
|
def LogOnce(self, logMsg = "", printTo = 0, logAlways = False, traceOnRemainingCalls = True):
|
||||||
|
if printTo == 0: printTo = self.LOG_TO_FILE
|
||||||
|
lineNo = inspect.currentframe().f_back.f_lineno
|
||||||
|
FuncAndLineNo = f"{inspect.currentframe().f_back.f_code.co_name}:{lineNo}"
|
||||||
|
if FuncAndLineNo in self.traceOncePreviousHits:
|
||||||
|
if traceOnRemainingCalls:
|
||||||
|
self.Trace(logMsg, printTo, logAlways, lineNo)
|
||||||
|
else:
|
||||||
|
self.traceOncePreviousHits.append(FuncAndLineNo)
|
||||||
|
self.Log(logMsg, printTo, logging.INFO, lineNo)
|
||||||
|
|
||||||
def Warn(self, logMsg, printTo = 0):
|
def Warn(self, logMsg, printTo = 0):
|
||||||
if printTo == 0: printTo = self.log_to_wrn_set
|
if printTo == 0: printTo = self.log_to_wrn_set
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ def start_library_monitor():
|
|||||||
# Iterate through stashPaths
|
# Iterate through stashPaths
|
||||||
for path in stashPaths:
|
for path in stashPaths:
|
||||||
observer.schedule(event_handler, path, recursive=RECURSIVE)
|
observer.schedule(event_handler, path, recursive=RECURSIVE)
|
||||||
plugin.Trace(f"Observing {path}")
|
plugin.Log(f"Observing {path}")
|
||||||
observer.schedule(event_handler, SPECIAL_FILE_DIR, recursive=RECURSIVE)
|
observer.schedule(event_handler, SPECIAL_FILE_DIR, recursive=RECURSIVE)
|
||||||
plugin.Trace(f"Observing FileMonitor path {SPECIAL_FILE_DIR}")
|
plugin.Trace(f"Observing FileMonitor path {SPECIAL_FILE_DIR}")
|
||||||
observer.start()
|
observer.start()
|
||||||
@@ -281,7 +281,7 @@ def start_library_monitor():
|
|||||||
break
|
break
|
||||||
if plugin.pluginSettings['turnOnScheduler']:
|
if plugin.pluginSettings['turnOnScheduler']:
|
||||||
checkSchedulePending()
|
checkSchedulePending()
|
||||||
plugin.Trace("Wait start")
|
plugin.LogOnce("Wait start")
|
||||||
signal.wait(timeout=SIGNAL_TIMEOUT)
|
signal.wait(timeout=SIGNAL_TIMEOUT)
|
||||||
plugin.Trace("Wait end")
|
plugin.Trace("Wait end")
|
||||||
shouldUpdate = False
|
shouldUpdate = False
|
||||||
|
|||||||
Reference in New Issue
Block a user