James, I apologize, I did not absorb the fact that you are using the Python logging package rather than the built-in Java logging. My advice below is not helpful.
Are you aware that you can use the Java logging from within scripts? I believe you can configure it to provide the various files you need. On Tue, Apr 4, 2017 at 11:35 AM, James McMahon <[email protected]> wrote: > How many distinct log files will that logback approach permit me James? I > have six different workflow paths for which I want to log to separate and > distinct log files. > > From this initialization, which of my python logging commands would stay > in initialize() and which would move to the logback.xml? > self.logger = logging.getLogger('nifi_ISP_1') > > self.logger.setLevel(logging.DEBUG) > > # establish a file handler… > > fh = logging.FileHandler('/home/nif > i/latest/logs/TestLog.log') > > fh.setLevel(logging.DEBUG) > > # create a formatter and associate it with our handler… > > formatter = logging.Formatter('%(asctime)-15s %(message)s') > > fh.setFromatter(formatter) > > self.logger.addHandler(fh) > > self.logger.info('Stooges 2020: Larry, Curley, Moe for > President') > > > So the problem here is that when I Stop the processor, the file handles > are not eliminated? The initialize() runs at Start only, but if it has been > stopped and started one or more times prior it inherits all that previous > baggage. Is that right? > > Thanks very much. > > Jim > > On Tue, Apr 4, 2017 at 2:18 PM, James Wing <[email protected]> wrote: > >> James, >> >> I suspect your call to self.logger.addHandler(fh) is cumulatively adding >> to your log results as initialize() is called again. Can you define the >> log file and formatting in your NiFi's conf/logback.xml (no restart >> required)? Then you can safely call getLogger() and access the shared >> configuration. >> >> >> Thanks, >> >> James >> >> On Tue, Apr 4, 2017 at 10:02 AM, James McMahon <[email protected]> >> wrote: >> >>> Good afternoon. I have been working to configure logging to a specific >>> log file that associates exclusively with one NiFi processor instance. I >>> understood from previous posts that InvokeScriptedProcessor processor lends >>> itself to this requirement. ISP allows for code that runs once - and only >>> once - when the processor is started. >>> >>> >>> >>> In this code snippet that follows I show how I establish my logging in >>> my ISP initialize() method. The problem I am having is that with each >>> stop/restart of the processor during test and development it appears that I >>> am initializing new instances of my logger following each restart of the >>> processor. After my first run my log has >>> >>> Stooges 2020… >>> >>> After my second run, >>> >>> Stooges 2020… >>> >>> Stooges 2020… >>> >>> After my third, >>> >>> Stooges 2020… >>> >>> Stooges 2020… >>> >>> Stooges 2020… >>> >>> And so on. After three runs of my ISP processor I have six log entries >>> rather than the three I expect. >>> >>> >>> >>> My code below is lacking something. How do I correct this error so that >>> I do not output N lines to the log file on run N? >>> >>> >>> >>> class UpdateProcessors(Processor) : >>> >>> >>> >>> def __init__(self) : >>> >>> self.__rel_success = Relationship.Builder().name("s >>> uccess").description("Success").build() >>> >>> >>> >>> def initialize(self, context) : >>> >>> try : >>> >>> # create a logger for this processor… >>> >>> self.logger = logging.getLogger('nifi_ISP_1') >>> >>> self.logger.setLevel(logging.DEBUG) >>> >>> # establish a file handler… >>> >>> fh = logging.FileHandler('/home/nif >>> i/latest/logs/TestLog.log') >>> >>> fh.setLevel(logging.DEBUG) >>> >>> # create a formatter and associate it with our handler… >>> >>> formatter = logging.Formatter('%(asctime)-15s >>> %(message)s') >>> >>> fh.setFromatter(formatter) >>> >>> self.logger.addHandler(fh) >>> >>> self.logger.info('Stooges 2020: Larry, Curley, Moe for >>> President') >>> >>> except : >>> >>> pass >>> >>> >>> >>> def getRelationships(self) : >>> >>> . >>> >>> . >>> >>> . >>> processor = UpdateAttributes() >>> >> >> >
