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(" > success").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/ > nifi/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() >
