question

Davide M. avatar image
Davide M. asked ·

How to create a custom logfile for python plugin?

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?

extensionsactivegatelinux
10 |2000000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 50.0 MiB each and 250.0 MiB total.

Davide M. avatar image
Davide M. answered ·

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

Share
10 |2000000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 50.0 MiB each and 250.0 MiB total.

Davide M. avatar image
Davide M. answered ·

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.

1 comment Share
10 |2000000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 50.0 MiB each and 250.0 MiB total.

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?

0 Likes 0 · ·
Julius L. avatar image
Julius L. answered ·

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.

Share
10 |2000000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 50.0 MiB each and 250.0 MiB total.