GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit a1bcd4a7 authored by Olof Svensson's avatar Olof Svensson

Added file logger

parent 7f2627e3
......@@ -24,14 +24,15 @@ __license__ = "MIT"
__date__ = "28/05/2019"
import os
import time
import pprint
import logging
import pathlib
import logging.handlers
from pypushflow import UtilsMongoDb
logger = logging.getLogger('pypushflow')
class Workflow(object):
......@@ -40,24 +41,45 @@ class Workflow(object):
self.listOnErrorActor = []
self.mongoId = UtilsMongoDb.initMongo(name=name)
self.listActorRef = []
self.logger = self.initLogger()
def connectOnError(self, actor):
logger.debug("In Workflow '{0}' connectOnError, actor name {1}".format(self.name, actor.name))
self.logger.debug("In Workflow '{0}' connectOnError, actor name {1}".format(self.name, actor.name))
self.listOnErrorActor.append(actor)
def triggerOnError(self, inData):
logger.debug("In Workflow '{0}' triggerOnError, inData:".format(self.name))
logger.debug(pprint.pformat(inData))
self.logger.debug("In Workflow '{0}' triggerOnError, inData:".format(self.name))
self.logger.debug(pprint.pformat(inData))
for onErrorActor in self.listOnErrorActor:
logger.debug("In Workflow '{0}' triggerOnError, triggering actor name {1}".format(self.name, onErrorActor.name))
self.logger.debug("In Workflow '{0}' triggerOnError, triggering actor name {1}".format(self.name, onErrorActor.name))
onErrorActor.trigger(inData)
def getActorPath(self):
return '/' + self.name
def addActorRef(self, actorRef):
logger.info("Adding actor ref: {0}".format(actorRef.name))
self.logger.info("Adding actor ref: {0}".format(actorRef.name))
self.listActorRef.append(actorRef)
def getListActorRef(self):
return self.listActorRef
def initLogger(self):
logger = logging.getLogger('pypushflow')
user = os.environ.get("USER", "unknown")
initiator = os.environ.get("PYPUSHFLOW_INITIATOR", "pypushflow")
log_file_dir = pathlib.Path("/tmp/{0}/{1}".format(user, initiator))
if not log_file_dir.exists():
log_file_dir.mkdir(mode=0o755, parents=True)
log_file_path = log_file_dir / "pypushfloww.log"
maxBytes = 1e6
backupCount = 10
fileHandler = logging.handlers.RotatingFileHandler(
log_file_path, maxBytes=maxBytes, backupCount=backupCount)
logFileFormat = '%(asctime)s %(levelname)-8s %(message)s'
formatter = logging.Formatter(logFileFormat)
fileHandler.setFormatter(formatter)
fileHandler.setLevel(logging.DEBUG)
logger.addHandler(fileHandler)
logger.info("Logging started")
return logger
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment