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 b, String a)
Required import: outsystems.hubedition.runtimeplatform.GenericExtendedActions
GenericExtendedActions.audit
Parameter Name | Parameter Type | Description | Max. Length |
---|---|---|---|
c | HeContext | The application context | |
b | String | Message to write to log | 2000 |
a | String | Module name | 15 |
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 Name | Parameter Type | Description | Max. Length |
---|---|---|---|
arg0 (i) | DateTime | The timestamp for the message | |
arg1 (h) | String | Session ID | 50 |
arg2 (g) | int | eSpace ID | |
arg3 (f) | int | Tenant ID | |
arg4 (e) | int | User ID | |
arg5 (d) | String | Message to write to log | 2000 |
arg6 (c) | String | Message type | 10 |
arg7 (b) | String | Module name | 15 |
arg8 (a) | String | Error identifier | 50 |
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 USER, INFO, WARNING.
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.
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 Name | Parameter Type | Description | Max. Length |
---|---|---|---|
i | DateTime | The timestamp for the message | |
h | String | Session ID | 50 |
g | int | eSpace ID | |
f | int | Tenant ID | |
e | int | User ID | |
d | String | Message to write to log | 2000 |
c | String | Error stack | - |
b | String | Environment information | 2000 |
a | String | Module name | 15 |
ErrorLog.staticWrite (overloaded)
Parameter Name | Parameter Type | Description | Max. Length |
---|---|---|---|
h | DateTime | The timestamp for the message | |
g | String | Session ID | 50 |
f | int | eSpace ID | |
e | int | Tenant ID | |
d | int | User ID | |
c | String | Message to write to log | 2000 |
b | String | Error stack | - |
a | String | Module name | 15 |
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 Name | Parameter Type | Description | Max. Length |
---|---|---|---|
arg0 | String | Error Id | 50 |
arg1 | DateTime | The timestamp for the message | |
arg2 | String | Session ID | |
arg3 | int | eSpace ID | |
arg4 | int | Tenant ID | |
arg5 | int | User ID | |
arg6 | String | Message to write to log | 2000 |
arg7 | String | Error stack | - |
arg8 | String | Environment information | 2000 |
arg9 | String | Module name | 15 |
arg10 | String | Request key | 36 |
arg11 | String | Entrypoint name | 60 |
arg12 | String | Action name | 60 |
arg13 | Boolean | ?? 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) | Datatype | Maximum # characters |
---|---|---|
ID | VARCHAR2 | 50 (CHAR) |
SESSION_ID | VARCHAR2 | 50 (CHAR) |
MESSAGE_TYPE | VARCHAR2 | 10 (CHAR) |
MESSAGE | VARCHAR2 | 2000 (CHAR) |
ERROR_ID | VARCHAR2 | 50 (CHAR) |
STACK | CLOB | |
MODULE_NAME | VARCHAR2 | 15 (CHAR) |
ENVIRONMENT_INFORMATION | VARCHAR2 | 2000 (CHAR) |
ENTRY_POINT | VARCHAR2 | 60 (CHAR) |
ACTION_NAME | VARCHAR2 | 60 (CHAR) |
REQUEST_KEY | VARCHAR2 | 36 (CHAR) |