今天试了一下在Activiti中使用log4j来进行配置发现这个会出现问题,其实Activiti中的日志系统是采用的是slf4j而不是log4j

然后使用slf4j驱动log4j来做的

通过ProcessEngineImpl中的源码可以看出

 /* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl; import java.util.Map; import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ManagementService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.cfg.TransactionContextFactory;
import org.activiti.engine.impl.el.ExpressionManager;
import org.activiti.engine.impl.interceptor.CommandExecutor;
import org.activiti.engine.impl.interceptor.SessionFactory;
import org.activiti.engine.impl.jobexecutor.JobExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; /**
* @author Tom Baeyens
*/
public class ProcessEngineImpl implements ProcessEngine { private static Logger log = LoggerFactory.getLogger(ProcessEngineImpl.class); protected String name;
protected RepositoryService repositoryService;
protected RuntimeService runtimeService;
protected HistoryService historicDataService;
protected IdentityService identityService;
protected TaskService taskService;
protected FormService formService;
protected ManagementService managementService;
protected JobExecutor jobExecutor;
protected CommandExecutor commandExecutor;
protected Map<Class<?>, SessionFactory> sessionFactories;
protected ExpressionManager expressionManager;
protected TransactionContextFactory transactionContextFactory;
protected ProcessEngineConfigurationImpl processEngineConfiguration; public ProcessEngineImpl(ProcessEngineConfigurationImpl processEngineConfiguration) {
this.processEngineConfiguration = processEngineConfiguration;
this.name = processEngineConfiguration.getProcessEngineName();
this.repositoryService = processEngineConfiguration.getRepositoryService();
this.runtimeService = processEngineConfiguration.getRuntimeService();
this.historicDataService = processEngineConfiguration.getHistoryService();
this.identityService = processEngineConfiguration.getIdentityService();
this.taskService = processEngineConfiguration.getTaskService();
this.formService = processEngineConfiguration.getFormService();
this.managementService = processEngineConfiguration.getManagementService();
this.jobExecutor = processEngineConfiguration.getJobExecutor();
this.commandExecutor = processEngineConfiguration.getCommandExecutor();
this.sessionFactories = processEngineConfiguration.getSessionFactories();
this.transactionContextFactory = processEngineConfiguration.getTransactionContextFactory(); commandExecutor.execute(processEngineConfiguration.getSchemaCommandConfig(), new SchemaOperationsProcessEngineBuild()); if (name == null) {
log.info("default activiti ProcessEngine created");
} else {
log.info("ProcessEngine {} created", name);
} ProcessEngines.registerProcessEngine(this); if ((jobExecutor != null) && (jobExecutor.isAutoActivate())) {
jobExecutor.start();
} if (processEngineConfiguration.getProcessEngineLifecycleListener() != null) {
processEngineConfiguration.getProcessEngineLifecycleListener().onProcessEngineBuilt(this);
}
} public void close() {
ProcessEngines.unregister(this);
if ((jobExecutor != null) && (jobExecutor.isActive())) {
jobExecutor.shutdown();
} commandExecutor.execute(processEngineConfiguration.getSchemaCommandConfig(), new SchemaOperationProcessEngineClose()); if (processEngineConfiguration.getProcessEngineLifecycleListener() != null) {
processEngineConfiguration.getProcessEngineLifecycleListener().onProcessEngineClosed(this);
}
} // getters and setters ////////////////////////////////////////////////////// public String getName() {
return name;
} public IdentityService getIdentityService() {
return identityService;
} public ManagementService getManagementService() {
return managementService;
} public TaskService getTaskService() {
return taskService;
} public HistoryService getHistoryService() {
return historicDataService;
} public RuntimeService getRuntimeService() {
return runtimeService;
} public RepositoryService getRepositoryService() {
return repositoryService;
} public FormService getFormService() {
return formService;
} public ProcessEngineConfigurationImpl getProcessEngineConfiguration() {
return processEngineConfiguration;
}
}

这两个有啥区别?自己google吧

pom.xml

         <!-- log4j -->
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>

添加log4j.properties

### set log levels ###
log4j.rootLogger = debug , stdout ### \u8F93\u51FA\u5230\u63A7\u5236\u53F0 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n ### \u8F93\u51FA\u5230\u65E5\u5FD7\u6587\u4EF6 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = logs/error.log \#\# \u5F02\u5E38\u65E5\u5FD7\u6587\u4EF6\u540D
log4j.appender.D.Append = true
log4j.appender.D.Threshold = ERROR \#\# \u53EA\u8F93\u51FAERROR\u7EA7\u522B\u4EE5\u4E0A\u7684\u65E5\u5FD7\!\!\!
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n

然后就可以使用了

你只要在java文件这样写就可以了

 package cn.lonecloud.mavenActivi;

 import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
//使用log4j导入的包
import org.apache.log4j.Logger;
import org.junit.Test;
//使用slf4j的导入的包
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory; public class InstanceDemo {
Logger logger=Logger.getLogger(this.getClass());
// Logger logger=LoggerFactory.getLogger(this.getClass());
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
TaskService taskService=processEngine.getTaskService();
@Test
public void testInstance(){
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Instance","Test02");
logger.debug("获取实例id"+processInstance.getId());
}
}

Activiti中的log4j(slf4j)的配置的更多相关文章

  1. Java log4j slf4j 日志配置笔记

    http://www.cnblogs.com/Scott007/p/3269018.html 日志的打印,在程序中是必不可少的,如果需要将不同的日志打印到不同的地方,则需要定义不同的Appender, ...

  2. manven springmvc 项目中 slf4j 的配置使用(结合log4j 或者 logback)

    前言:每个maven springmvc 都应该有日志功能,SLF4J(Simple logging facade for Java)就是一种日志规范,它提供了一个共通接口,可以适配多种不同的LOG实 ...

  3. 【Java】日志知识总结和经常使用组合配置(commons-logging,log4j,slf4j,logback)

    Log4j Apache的一个开放源码项目,通过使用Log4j,我们能够控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口服务 器.NT的事件记录器.UNIX Syslog守护进程等.用 ...

  4. Log4j slf4j 配置简单介绍

    Log4j slf4j 配置简单介绍 先借鉴一篇很好的文章 为什么要使用SLF4J而不是Log4J import org.slf4j.Logger; import org.slf4j.LoggerFa ...

  5. 基于Storm的工程中使用log4j

    最近使用Storm开发,发现log4j死活打不出debug级别的日志,网上搜到的关于log4j配置的方法都试过了,均无效. 最终发现问题是这样的:最新的storm使用的日志系统已经从log4j切换到了 ...

  6. Java日志框架 (commons-logging,log4j,slf4j,logback)

    转自:http://blog.csdn.net/kobejayandy/article/details/17335407 如果对于commons-loging.log4j.slf4j.LogBack等 ...

  7. spring学习总结(mybatis,事务,测试JUnit4,日志log4j&slf4j,定时任务quartz&spring-task,jetty,Restful-jersey等)

    在实战中学习,模仿博客园的部分功能.包括用户的注册,登陆:发表新随笔,阅读随笔:发表评论,以及定时任务等.Entity层设计3张表,分别为user表(用户),essay表(随笔)以及comment表( ...

  8. (转)log4j(六)——log4j.properties简单配置样例说明

    一:测试环境与log4j(一)——为什么要使用log4j?一样,这里不再重述 1 老规矩,先来个栗子,然后再聊聊感受 (1)使用配文件的方式,是不是感觉非常的清爽,如果不在程序中读取配置文件就更加的清 ...

  9. 如何实现Activiti的分支条件的自定义配置(转)

    如何实现Activiti的分支条件的自定义配置 博客分类: Activiti Java SaaS   一.Activiti的流程分支条件的局限 Activiti的流程分支条件目前是采用脚本判断方式,并 ...

随机推荐

  1. LINUX文档管理命令

    body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...

  2. (2-3)Eureka详解

    基础架构 服务注册中心 服务提供者 服务消费者 服务治理 服务提供者 服务注册.在服务注册时,需要确认一下eureka.client.registerwith-eurek=ture参数是否正确,默认是 ...

  3. 自己写的日志框架--linkinLog4j--框架可配置+提性能

    OK,上一篇博客我们已经实现了日志框架的基本的功能,但是还有一个最大的问题就是日志输出地不能重定向,然后一些输出也不可控.那现在我们来实现一个比较完整的日志框架. 设计思路如下: 1,定义一堆常量Li ...

  4. sed替换文本

    [root@localhost.localdomain home]#cat test ### @2=1492785988 /* INT meta=0 nullable=0 is_null=0 */ # ...

  5. TCP/IP网络协议基础知识集锦[转]

    引言 本篇属于TCP/IP协议的基础知识,重点介绍了TCP/IP协议簇的内容.作用以及TCP.UDP.IP三种常见网络协议相关的基础知识. 内容 TCP/IP协议簇是由OSI七层模型发展而来的,之所以 ...

  6. 【Thinkphp 5】 如何引入extend拓展文件

    extend/maile/cc.php 文件目录 cc文件 必须要加上命名空间,如下 cc.php文件内容如下: namespace maile; //命名空间 maile是文件夹名称 class C ...

  7. awk运用

    awk编程: 1. 变量: 在awk中变量无须定义即可使用,变量在赋值时即已经完成了定义.变量的类型可以是数字.字符串.根据使用的不同,未初始化变量的值为0或空白字符串" ",这主 ...

  8. linux tar 压缩解压命令

    tar命令: -c 压缩-x 解压缩-t 不解压的情况下查看文件内容-r 向压缩文件追加文件-u 更新压缩文件 以上参数必须和'-f'参数连用,且'-f'必须为最后一个参数,后接文档名 -z 对应gz ...

  9. window对象的属性

    还不是很了解,以后补充frames      opener       parent

  10. tensorflow Image 解码函数

    觉得有用的话,欢迎一起讨论相互学习~Follow Me tf.image.decode_png(contents, channels=None, name=None) Decode a PNG-enc ...