OutSystems – Java extension: write log messages

I was looking for a way to debug an (Java) extension and found some posts about this on the OutSystems community. Of course most of these posts are on .NET, but Java or .NET, debugging an extension is not that easy. The easiest way to enable some sort of debugging for an extension, is to write (debug) messages to the OutSystems general log, that you can access via ServiceCenter or directly from the table OSADMIN.OSLOG_GENERAL.

There are 2 options for writing messages to the general log, one using the write (or staticWrite) method in the GeneralLog class and the other using the audit method in the GenericExtendedActions class. The easiest method to use, is the GenericExtendedActions.audit method.

GenericExtendedActions.audit(HeContext c, String bString a)

Required import: outsystems.hubedition.runtimeplatform.GenericExtendedActions

GenericExtendedActions.audit

Parameter NameParameter TypeDescriptionMax. Length
cHeContextThe application context
bStringMessage to write to log2000
aStringModule name15

An example of using GenericExtendedActions.audit where it will write the message “Message to write” to OutSystems log table with a module name called “MyModule”.

GenericExtendedActions.audit(AppInfo.getAppInfo().getOsContext(), "Message to write", "MyModule");

The specified module does not need to be the name of an existing eSpace. You should use a logical name that you can use later to filter the messages in the General Log page of Service Center.

GeneralLog.write(DateTime arg0, String arg1, int arg2, int arg3, int arg4, String arg5, String arg6, String arg7, String arg8)

Required import: outsystems.hubedition.runtimeplatform.log.GeneralLog

.write and GeneralLog.staticWrite

Parameter NameParameter TypeDescriptionMax. Length
arg0 (i)DateTimeThe timestamp for the message
arg1 (h)StringSession ID50
arg2 (g)inteSpace ID
arg3 (f)intTenant ID
arg4 (e)intUser ID
arg5 (d)StringMessage to write to log2000
arg6 (c)StringMessage type10
arg7 (b)StringModule name15
arg8 (a)StringError identifier50

An example of using GeneralLog.write where it will write the message “Message to write” to OutSystems log table with a module name called “MyModule”.

GeneralLog osLog = new GeneralLog();
osLog.write(DateTime.getNow(), AppInfo.getAppInfo().getOsContext().getSession().getSessionID(), AppInfo.getAppInfo().geteSpaceId() , AppInfo.getAppInfo().getTenant().getId(), AppInfo.getAppInfo().getOsContext().getSession().getUserId(), "Message to write", "USER", "MyModule", " ");

There’s also a static version of the write method available, named staticWrite, so you can also use:

GeneralLog.staticWrite(DateTime.getNow(), AppInfo.getAppInfo().getOsContext().getSession().getSessionID(), AppInfo.getAppInfo().geteSpaceId() , AppInfo.getAppInfo().getTenant().getId(), AppInfo.getAppInfo().getOsContext().getSession().getUserId(), "Message to write", "USER", "MyModule", " ");

For the Message Type specify one of USERINFOWARNING.

The specified Module Name does not need to be the name of an existing eSpace. You should use a logical name that you can use later to filter the messages in the General Log page of Service Center.

The screendump taken from the ServiceCenter General log output, filtered on “MyModule”, show the messages inserted into the log table using both the GenericExtendedActions.audit and GeneralLog.staticWrite methods.

OutSystems General Log Screen

OutSystems General Log Screen

Writing to the Error Log

Besides writing messages to the OutSystems General log table, you can also write messages to the OutSystems Error log table (OSADMIN.OSLOG_ERROR). To be able to write messages to this log table, you can use the staticWrite method  from the ErrorLog class. It is an overloaded method (with the shorter version you cannot specify the environment information), and the parameter tables below show the description of each parameter.

ErrorLog.staticWrite

Parameter NameParameter TypeDescriptionMax. Length
iDateTimeThe timestamp for the message
hStringSession ID50
ginteSpace ID
fintTenant ID
eintUser ID
dStringMessage to write to log2000
cStringError stack-
bStringEnvironment information2000
aStringModule name15

ErrorLog.staticWrite (overloaded)

Parameter NameParameter TypeDescriptionMax. Length
hDateTimeThe timestamp for the message
gStringSession ID50
finteSpace ID
eintTenant ID
dintUser ID
cStringMessage to write to log2000
bStringError stack-
aStringModule name15

Example of using the staticWrite method (the one including the environment information parameter):

ErrorLog.staticWrite(DateTime.getNow(), AppInfo.getAppInfo().getOsContext().getSession().getSessionID(), AppInfo.getAppInfo().geteSpaceId() , AppInfo.getAppInfo().getTenant().getId(), AppInfo.getAppInfo().getOsContext().getSession().getUserId(), "Message to write", "Error stack", "Env. info", "MyModule");

To use the write method available in an ErrorLog object, the following parameters are used.

.write

Parameter NameParameter TypeDescriptionMax. Length
arg0StringError Id50
arg1DateTimeThe timestamp for the message
arg2StringSession ID
arg3inteSpace ID
arg4intTenant ID
arg5intUser ID
arg6StringMessage to write to log2000
arg7StringError stack-
arg8StringEnvironment information2000
arg9StringModule name15
arg10StringRequest key36
arg11StringEntrypoint name60
arg12StringAction name60
arg13Boolean?? Should be true

Example of using the write method:

ErrorLog osErr = new ErrorLog();
 osErr.write("MyErrorId", DateTime.getNow(), AppInfo.getAppInfo().getOsContext().getSession().getSessionID(), AppInfo.getAppInfo().geteSpaceId() , AppInfo.getAppInfo().getTenant().getId(), AppInfo.getAppInfo().getOsContext().getSession().getUserId(), "Message to write", "Errors in stack", "Env. info", "MyModule", "Request KEY", "MyEntryPoint", "MyAction", true);

Maximum length of “log” table columns

The following table lists the maximum length of the various “text” fields in the “General” and “Error” log tables. I have mentioned the maximum length for these text fields in the parameter tables above, so this table is just a recap of this information together with the accompying column names that are used in the database tables.

OutSystems log table attribute maxsize

Attribute (column)DatatypeMaximum # characters
IDVARCHAR250 (CHAR)
SESSION_IDVARCHAR250 (CHAR)
MESSAGE_TYPEVARCHAR210 (CHAR)
MESSAGEVARCHAR22000 (CHAR)
ERROR_IDVARCHAR250 (CHAR)
STACKCLOB
MODULE_NAMEVARCHAR215 (CHAR)
ENVIRONMENT_INFORMATIONVARCHAR22000 (CHAR)
ENTRY_POINTVARCHAR260 (CHAR)
ACTION_NAMEVARCHAR260 (CHAR)
REQUEST_KEYVARCHAR236 (CHAR)

Leave a Reply

Your email address will not be published. Required fields are marked *