How can i write log entries by a script?

Any issue about Cyclos 4 scripting and Webservices

Moderators: hugo, alexandre, rmvanarkel

Post Reply
admin_de2
Posts: 60
Joined: Wed Dec 31, 1969 9:00 pm

How can i write log entries by a script?

Post by admin_de2 »

Dear Cyclosians,

How can log entries be written from a script so they appear in the log
file of the corresponding network? Println() is surely no clean way
and only outputs to the Tomcat log in catalina.out

Thank you, Thomas & Jakob

luis
Posts: 192
Joined: Fri Feb 17, 2006 11:01 am

Re: How can i write log entries by a script?

Post by luis »

By "log file of the corresponding network" you mean the services log?
It is not possible to directly log to that file from script, it is very specific for logging service calls.
To log in Tomcat's catalina.out, you can use Log4j2, like this:

Code: Select all

import org.apache.logging.log4j.LogManager

def logger = LogManager.getLogger("script")
logger.info("Information message")
logger.warn("Warning message")
logger.error("Error message", new NullPointerException())
Luis Fernando Planella Gonzalez
Cyclos development team

admin_de2
Posts: 60
Joined: Wed Dec 31, 1969 9:00 pm

Re: How can i write log entries by a script?

Post by admin_de2 »

Hi Luis,

is there a possibility to write log entries to the logs i can see as admin under menu Reports -> System alerts and Reports -> User alerts or Reports -> Error logs?

Thank you, Th.

luis
Posts: 192
Joined: Fri Feb 17, 2006 11:01 am

Re: How can i write log entries by a script?

Post by luis »

Use the errorLogService.create method: https://documentation.cyclos.org/4.13/s ... BasicUser-

It has 4 parameters. The service / method name, the error stack trace (but you could put any text on it), the channel (you can use sessionData.channel) and the logged user or operator (you can use sessionData.loggedBasicUser).
Luis Fernando Planella Gonzalez
Cyclos development team

jakob.schumann
Posts: 15
Joined: Thu Apr 23, 2020 5:37 pm

Re: How can i write log entries by a script?

Post by jakob.schumann »

Thanks for the hint, but using

Code: Select all

errorLogService.create("PaymentService.preview", "test message", sessionData.channel, sessionData.loggedBasicUser)
in a custom field validator causes
There was an error while accessing the database
to be displayed instead of the validators error message. The catalina.out still (only) contains the error message like it normally would (without this additional line in the script):

Code: Select all

[2020-07-16 19:09:34] [info] 2020-07-16T19:09:34.845+02:00 ERROR ServiceInvokerHandlerImpl - Error on service method public abstract org.cyclos.model.banking.transactions.PaymentPreviewVO org.cyclos.services.banking.PaymentService.preview(org.cyclos.model.banking.transactions.PerformPaymentDTO) throws org.cyclos.model.FrameworkException
[2020-07-16 19:09:34] [info] org.cyclos.model.ValidationException: Custom field errors:
[2020-07-16 19:09:34] [info]  * ones
[2020-07-16 19:09:34] [info]  * # Gutscheinsumme (25.00 %currency%) entspricht nicht dem angegebenen Gesamtbetrag!
Best regards,
Jakob

jamesmorgan007
Posts: 1
Joined: Thu Sep 24, 2020 1:42 pm
Contact:

Re: How can i write log entries by a script?

Post by jamesmorgan007 »

To write the output of Bash Command to Log File, you may use the right angle bracket symbol (>) or double right angle symbol (>>). Right angle bracket symbol (>): is used to write the output of a bash command to a disk file. If the file is not already present, it creates one with the name specified.
I hope it will work for you.
Best Regards
James morgan
IVR System Specialist

Post Reply