The Audit log provides a comprehensive and informative view of the execution of a specific task. It makes it easy for users to find the information they need and troubleshoot problems. This is also useful for pulling audit reports such as who updated a certain record, any access controle rules violation, etc.
LogApi class is used for logging. In turn, it makes use of the information in the context to log a few information such as flowExecId, taskExecId, transactionId, etc.
Types of Logging
Standard logging: Log basic information using log4j to the console. These show up in the stackdriver logs in the cloud).
LogApi.info("Hello world"); // Standard logging
Audit logging: It logs into DB and also to the console. It has an additional level called “critical” (maps to error for the log4j logging). These logs are collected in the MySql DB. These should be used for important business-level signals.
Standard logging along with Result response: It is similar to basic logging, but it also returns a result object. This is useful to log and construct a Result object (for critical, errors, it constructs a “failed” result, for others it constructs “success”). This should be used when you want to log a message and also return the same message in a Result object. This avoids making two calls one to log and another to construct a Result object.
LogApi.infoR("Hello world", "response", res); // Standard logging along with Result response
Audit logging along with Result response: t is similar to audit logging, but it also returns a result object. This should be used when you want to audit log the message and also return the same message in a Result object. This avoids making two calls one to log and another to construct a Result object.
LogApi.auditInfoR("action", "summary", "details", "sourceUid", "response", res) //Audit logging along with Result response
Complete Logging API
publicclassLogApi {// Standard logspublicstaticfinalvoiddebug(String msg,Object... args) {... }publicstaticfinalvoiddebug(String msg,Throwable t,Object... args) {... }publicstaticfinalvoidinfo(String msg,Object... args) {... }publicstaticfinalvoidinfo(String msg,Throwable t,Object... args) {... }publicstaticfinalvoidwarn(String msg,Object... args) {... }publicstaticfinalvoidwarn(String msg,Throwable t,Object... args) {... }publicstaticfinalvoiderror(String msg,Object... args) {... }publicstaticfinalvoiderror(String msg,Throwable t,Object... args) {... }publicstaticfinalResultinfoR(String msg,Object... args) {... }// standard logs that return Result object.// It ensures that logged and returned messages are same and avoid extra // formatting call.publicstaticfinalResultinfoR(String msg,Throwable t,Object... args) {... }publicstaticfinalResultwarnR(String msg,Object... args) {... }publicstaticfinalResultwarnR(String msg,Throwable t,Object... args) {... }publicstaticfinalResulterrorR(String msg,Object... args) {... }publicstaticfinalResulterrorR(String msg,Throwable t,Object... args) {... }publicstaticfinalResulterrorR(String msg) {... }// Audit logs - logs on to console and make a record in the database.publicstaticfinalvoidauditLog(Map<String,Object> logObject) {... }publicstaticfinalvoidauditLog(Map<String,Object> logObject,boolean permitLogging) {... }publicstaticfinalvoidauditInfo(String action,String summary,Object detail,String sourceUid,Object ...args) {... }publicstaticfinalvoidauditWarn(String action,String summary,Object detail,String sourceUid,Object ...args) {... }publicstaticfinalvoidauditError(String action,String summary,Object detail,String sourceUid,Object ...args) {... } public static final void auditCritical(String action, String summary, Object detail, String sourceUid, Object ...args) {
... }// a variation of above methods that require no detail and sourceUidpublicstaticfinalvoidauditInfo2(String action,String summary,Object...args) {... }publicstaticfinalvoidauditWarn2(String action,String summary,Object...args) {... }publicstaticfinalvoidauditError2(String action,String summary,Object...args) {... }publicstaticfinalvoidauditCritical2(String action,String summary,Object...args) {... }//audit logs that return Result object.// It ensures that logged and returned messages are same and avoid extra // formatting call. public static final Result auditInfoR(String action, String summary, Object detail, String sourceUid, Object ...args) {
... } public static final Result auditWarnR(String action, String summary, Object detail, String sourceUid, Object ...args) {
... } public static final Result auditErrorR(String action, String summary, Object detail, String sourceUid, Object ...args) {
... } public static final Result auditCriticalR(String action, String summary, Object detail, String sourceUid, Object ...args) {
... }publicstaticfinalResultauditInfo2R(String action,String summary,Object...args) {... }publicstaticfinalResultauditWarn2R(String action,String summary,Object...args) {... }publicstaticfinalResultauditError2R(String action,String summary,Object...args) {... }publicstaticfinalResultauditCritical2R(String action,String summary,Object...args) {... }}