Camunda 7
支持的日志级别为:None
、Activity
、Audit
、Full
,记录的信息逐级增加,None
和Activity
不会记录流传变量,可以显著提升引擎性能,如果在项目中有诉求需要对历史日志自定义记录,也可以通过实现HistoryLevel
接口或者继承已有的历史日志类进行能力扩展。
自定义日志需要通过继承 AbstractProcessEnginePlugin
类进行注册,相关示例如下:
1 2 3 4 5 6 7 8 9 10 11 12 13
| @Component public class CustomHistoryLevelProcessEnginePlugin extends AbstractProcessEnginePlugin {
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) { List<HistoryLevel> customHistoryLevels = processEngineConfiguration.getCustomHistoryLevels(); if (customHistoryLevels == null) { customHistoryLevels = new ArrayList<HistoryLevel>(); processEngineConfiguration.setCustomHistoryLevels(customHistoryLevels); } customHistoryLevels.add(CustomVariableHistoryLevel.getInstance());
} }
|
在Spring Boot项目中,需要将CustomHistoryLevelProcessEnginePlugin
注册为Bean
通过接口实现日志事件类型判断:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public class CustomVariableHistoryLevel implements HistoryLevel {
public static final CustomVariableHistoryLevel INSTANCE = new CustomVariableHistoryLevel();
public static CustomVariableHistoryLevel getInstance() { return INSTANCE; }
public int getId() { return 11; }
public String getName() { return "custom-variable"; }
public boolean isHistoryEventProduced(HistoryEventType historyEventType, Object entity) { }
}
|
也可以通过继承已有的日志类进行能力扩展:
1 2 3
| public class CustomVariableHistoryLevel extends HistoryLevelActivity { }
|
参考:https://github.com/camunda/camunda-bpm-examples/blob/master/process-engine-plugin/custom-history-level/README.md