Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function to send messages to MessageLog #621

Closed
PiotrRajtar opened this issue Sep 30, 2021 · 7 comments
Closed

Add a function to send messages to MessageLog #621

PiotrRajtar opened this issue Sep 30, 2021 · 7 comments

Comments

@PiotrRajtar
Copy link

It would be useful for tm1py to allow sending messages to the MessageLog, so that they can be easily browsed and picked up by Pulse alerts.

Currently I am doing something similar using an unbound TI, but is not ideal as whitespaces have to be replaced with some other separator, e.g. underscore, otherwise they get removed:

                logging.exception(f"Unable to send values to cube [{log_cube}].")
                self.tm1.processes.execute_ti_code(f"LogOutput('ERROR', 'TM1py_[{path.basename(__file__)}]"
                                                   f"_{type(ex).__name__}__Please_check_[{LOG_FILE}]_for_details.');")

Ideally, the function should be supported as a custom logging handler in the logging module.

@zsoltmoravcsik
Copy link

zsoltmoravcsik commented Sep 30, 2021 via email

@rkvinoth
Copy link
Contributor

rkvinoth commented Oct 1, 2021

@PiotrRajtar I don't think there is a way to add LOGOUTPUT via REST API (I could be wrong).

But the unboundTI way works. The issue with your code is that, execute_ti_code method expects an iterable but you are passing a str. It is trying to convert your str into an iterable and that is why the whitespaces are getting removed.
This should work:

try:
    pass
except Exception as ex:
    logging.exception(f"Unable to send values to cube [{log_cube}].")
    self.tm1.processes.execute_ti_code(lines_prolog=[f"LogOutput('ERROR', 'TM1py [{path.basename(__file__)}] "
                                                     f"{type(ex).__name__} please check [{LOG_FILE}] for details.');"])

I highly recommend the usage of parameter names (lines_prolog) in the code (though it is the only mandatory parameter), as it makes the code more readable.

@MariusWirtz Would it be possible to build a custom method that would take the loglevel and message then write it to the serverlog using TI (we can have the require_admin decorator)?

@MariusWirtz
Copy link
Collaborator

Good point @rkvinoth. The function expects an iterable. I oversaw this.
AFAIK we have to use unbound ti processes for writing to the message log.

@rkvinoth please feel free to open a Pull Request!

@gbryant-dev
Copy link
Contributor

@MariusWirtz @rkvinoth If no one is already picking this up, I would be happy to raise a PR for this for my first contribution to TM1py!

Let me know :)

@rkvinoth
Copy link
Contributor

That would be awesome. Currently I'm engaged with other stuff.

Thanks!

@gbryant-dev
Copy link
Contributor

Here's the PR #639 :)

@MariusWirtz
Copy link
Collaborator

Closed with #639

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants