Here is definition of my class full of static functions. I want to use all of them in "sendLog" function which call himself with time interval (10 sec here). When I run this interpreter tells me "TypeError: sendLog() takes at least 5 arguments (0 given)" But it if I enter the same params I will need to define sendLog again and again because it calls himself repeatly.. I know its not the way But cant figure it out.
class AccessLog:
@staticmethod
def backupAccessLog(target, source):
newfile = os.path.splitext(source)[0] + "_" + time.strftime("%Y%m%d-%H%M%S") + os.path.splitext(source)[1]
copyfile(source,newfile)
shutil.move(newfile,target)
@staticmethod
def emptyAccessLog(filename):
open(filename, 'w').close()
@staticmethod
def postLogstoElastic():
fileLogs = open("example.log", "rw+")
fileBackups = open("logs_of_accesslog.log","rw+")
lines = fileLogs.read().splitlines()
logging.basicConfig(format='%(asctime)s>>>%(message)s',filename='logs_exceptions.log',level=logging.DEBUG)
es = Elasticsearch(['http://localhost:9200/'], verify_certs=True)
#es.create(index="index_log23June", doc_type="type_log23June")
es.indices.create(index='index_log23June', ignore=400)
i=0
for item in lines:
try:
i+=1
if bool(item):
es.index(index="index_log23June",doc_type="type_log23June", body={"Log":item})
else:
print "a speace line ignored. at line number:", i
raise ValueError('Error occurred on this line: ', i)
print "lines[",i,"]:",item,"\n"
except ValueError as err:
logging.error(err.args)
@staticmethod
def sendLog(interval, worker_functions, iterations=1):
def call_worker_functions():
for f in worker_functions:
f() #ERROR: Msg: 'NoneType' object is not callable
for i in range(iterations):
threading.Timer(interval * i, call_worker_functions).start()
and I want to call this method with this line:
try:
AccessLog.AccessLog.sendLog(
interval=10,
worker_functions=(
AccessLog.AccessLog.backupAccessLog("logbackups","example.log"),
AccessLog.AccessLog.emptyAccessLog("example.log"),
AccessLog.AccessLog.postLogstoElastic()
),
iterations=999
)
except ValueError as err:
logging.error(err.args)
"TypeError: sendLog() takes at least 5 arguments (0 given)" It looks normal but How can I handle this ?