The simplest way to set up the entity log is using the
application screen. The process of manual set up is described below.Logging is configured using the LoggedEntity
and LoggedAttribute
entities corresponding to SEC_LOGGED_ENTITY and SEC_LOGGED_ATTR tables.
LoggedEntity
defines the types of entities that should be logged. LoggedEntity
has the following attributes:
-
name
(NAME column) – the name of the entity meta-class, for example,sales$Customer
. -
auto
(AUTO column) – defines if the system should log the changes when EntityLogAPI is called withauto = true
parameter (i.e. called by entity listeners). -
manual
(MANUAL column) – defines if the system should log the changes whenEntityLogAPI
is called withauto = false
parameter.
LoggedAttribute
defines the entity attribute to be logged and contains a link to the LoggedEntity
and the attribute name.
To set up logging for a certain entity, the corresponding entries should be added into the SEC_LOGGED_ENTITY and SEC_LOGGED_ATTR tables. For example, logging the changes to name
and grade
attributes of the Customer
entity can be enabled using:
insert into SEC_LOGGED_ENTITY (ID, CREATE_TS, CREATED_BY, NAME, AUTO, MANUAL) values ('25eeb644-e609-11e1-9ada-3860770d7eaf', now(), 'admin', 'sales$Customer', true, true); insert into SEC_LOGGED_ATTR (ID, CREATE_TS, CREATED_BY, ENTITY_ID, NAME) values (newid(), now(), 'admin', '25eeb644-e609-11e1-9ada-3860770d7eaf', 'name'); insert into SEC_LOGGED_ATTR (ID, CREATE_TS, CREATED_BY, ENTITY_ID, NAME) values (newid(), now(), 'admin', '25eeb644-e609-11e1-9ada-3860770d7eaf', 'grade');
To activate the logging mechanism, the Enabled
attribute of the app-core.cuba:type=EntityLog
JMX bean should be set to true
. The changes to logging settings made at runtime are applied after server restart or after calling invalidateCache()
method of the same bean.