cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to create a custom logfile for python plugin?

dmascolo
Newcomer

Hi there,
I'm developing a custom python plugin and I would like to have a dedicated logfile where I can track execution information.
I'm not a python expert neither a developer, so any suggest will be really appreciated!
I used the following command:

import logging

logging.basicConfig(format='%(asctime)s -%(levelname)s- %(message)s',

datefmt='%Y-%m-%d %H:%M:%S',

filename='/tmp/my_plugin.log',

level=logging.INFO)

Entries in logfile are added using the following command (just an example):

logging.info('start of plugin execution')


If I run the script from the command line, it works and some information are added to logfile.

Unfortunately, if the script is run by activegate no information is added to log.

Can you suggest me how to do in order to manage a custom logfile?

4 REPLIES 4

Julius_Loman
Leader

AFAIK every ActiveGate plugin has its own dedicated log file. Why are you in a need to use a custom one?

The remotepluginmodule will take care of log rotation and sizes.

My code:


logger = logging.getLogger(__name__)

class SomePluginRemote(RemoteBasePlugin):
    def initialize(self, **kwargs
        logger.info(kwarg
    def query(self, **kwargs
        logger.info(kwargs)

This will log the entries in /var/lib/dynatrace/remotepluginmodule/log/remoteplugin/<your_plugin>

on Linux or in ProgramData directory on Windows ActiveGate.

dmascolo
Newcomer

Hi Julius, I would like to give this log file to customer in order to have a "clean" view of the steps performed by plugin.

I understand the requirement to log information, but I don't understand why the plugin log file does not fit your use case. Do you need two or more logfiles from same plugin?

dmascolo
Newcomer

Hi Julius, my idea was to centralize all the information in a single log.

Unfortunately at the moment the plugin sends data that I would like to log in two different file:

-/var/lib/dynatrace/remotepluginmodule/log/remoteplugin/<your_plugin>/<mypluginname>
and
-/var/lib/dynatrace/remotepluginmodule/log/remoteplugin/ruxitagent_remotepluginagent_*.log


My code is:


class MYPlugin(RemoteBasePlugin):


def initialize(self, **kwargs):

logger.info('Config: %s', self.config)

self.url = self.config.get('url')

self.dblist = self.config.get('db_lista')

self.terlist = self.config.get('cerca_ter')

self.minuti = self.config.get('intervallo')


logger.info('variabile url: %s', self.url)

logger.info('variabile db : %s', self.dblist)

logger.info('variabile ter: %s', self.terlist)

logger.info('variabile min: %s', self.minuti)


def query(self, **kwargs):

outputCmd = requests.get(self.url + '/be/rest/killsession/search').json()

logger.info('output url: %s', outputCmd)


variables related to initialize session are logged in the second file, while outputCmd result is logged in the right file.


Any suggestion? Thanks in advance.

Davide