log4j+mongodb
maven 配置:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.8.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.log4mongo</groupId>
<artifactId>log4mongo-java</artifactId>
<version>0.7.4</version>
</dependency>
log4j.properties
#MongoDB
log4j.logger.MongoDB=INFO,MongoDB
log4j.appender.MongoDB=org.log4mongo.MongoDbAppender
log4j.appender.MongoDB.databaseName=mq
log4j.appender.MongoDB.collectionName=log
log4j.appender.MongoDB.hostname=mongoDB
log4j.appender.MongoDB.port=27017
log4j.appender.MongoDB.Append = true
log4j.appender.MongoDB.Threshold = INFO
测试类
private static final Logger logger = LoggerFactory.getLogger("MongoDB"); public void testLog() throws Exception {
logger.info("testMongoDbLog"); }
进入mongodb查看
> use mq
switched to db mq
> db.log.find();
{ "_id" : ObjectId("584e00a75f519d16cc41746f"), "timestamp" : ISODate("2016-12-12T01:43:03.165Z"), "level" : "INFO", "thread" : "qtp632707967-34", "message" : "mongodb log info", "loggerName" : { "fullyQualifiedClassName" : "MongoDB", "package" : [ "MongoDB" ], "className" : "MongoDB" }, "fileName" : "UserInfoController.java", "method" : "testLog", "lineNumber" : "155", "class" : { "fullyQualifiedClassName" : "com.shanjin.mq.controller.UserInfoController", "package" : [ "com", "shanjin", "mq", "controller", "UserInfoController" ], "className" : "UserInfoController" }, "host" : { "process" : "5836@PC-20160604TRVJ", "name" : "PC-20160604TRVJ", "ip" : "192.168.1.33" } }
{ "_id" : ObjectId("584e00a75f519d1630e15735"), "timestamp" : ISODate("2016-12-12T01:43:03.220Z"), "level" : "INFO", "thread" : "DubboServerHandler-192.168.1.33:20882-thread-3", "message" : "UserInfoServiceImpl log", "loggerName" : { "fullyQualifiedClassName" : "MongoDB", "package" : [ "MongoDB" ], "className" : "MongoDB" }, "fileName" : "UserInfoServiceImpl.java", "method" : "testLog", "lineNumber" : "178", "class" : { "fullyQualifiedClassName" : "com.shanjin.mq.service.impl.UserInfoServiceImpl", "package" : [ "com", "shanjin", "mq", "service", "impl", "UserInfoServiceImpl" ], "className" : "UserInfoServiceImpl" }, "host" : { "process" : "5680@PC-20160604TRVJ", "name" : "PC-20160604TRVJ", "ip" : "192.168.1.33" } }
{ "_id" : ObjectId("584e00a75f519d16cc417470"), "timestamp" : ISODate("2016-12-12T01:43:03.192Z"), "level" : "ERROR", "thread" : "qtp632707967-34", "message" : "mongodb log error", "loggerName" : { "fullyQualifiedClassName" : "MongoDB", "package" : [ "MongoDB" ], "className" : "MongoDB" }, "fileName" : "UserInfoController.java", "method" : "testLog", "lineNumber" : "156", "class" : { "fullyQualifiedClassName" : "com.shanjin.mq.controller.UserInfoController", "package" : [ "com", "shanjin", "mq", "controller", "UserInfoController" ], "className" : "UserInfoController" }, "host" : { "process" : "5836@PC-20160604TRVJ", "name" : "PC-20160604TRVJ", "ip" : "192.168.1.33" } }
{ "_id" : ObjectId("584e010e5f519d16cca462d0"), "timestamp" : ISODate("2016-12-12T01:44:46.602Z"), "level" : "INFO", "thread" : "qtp632707967-30", "message" : "mongodb log info", "loggerName" : { "fullyQualifiedClassName" : "MongoDB", "package" : [ "MongoDB" ], "className" : "MongoDB" }, "fileName" : "UserInfoController.java", "method" : "testLog", "lineNumber" : "155", "class" : { "fullyQualifiedClassName" : "com.shanjin.mq.controller.UserInfoController", "package" : [ "com", "shanjin", "mq", "controller", "UserInfoController" ], "className" : "UserInfoController" }, "host" : { "process" : "5836@PC-20160604TRVJ", "name" : "PC-20160604TRVJ", "ip" : "192.168.1.33" } }
{ "_id" : ObjectId("584e010e5f519d16cca462d1"), "timestamp" : ISODate("2016-12-12T01:44:46.628Z"), "level" : "ERROR", "thread" : "qtp632707967-30", "message" : "mongodb log error", "loggerName" : { "fullyQualifiedClassName" : "MongoDB", "package" : [ "MongoDB" ], "className" : "MongoDB" }, "fileName" : "UserInfoController.java", "method" : "testLog", "lineNumber" : "156", "class" : { "fullyQualifiedClassName" : "com.shanjin.mq.controller.UserInfoController", "package" : [ "com", "shanjin", "mq", "controller", "UserInfoController" ], "className" : "UserInfoController" }, "host" : { "process" : "5836@PC-20160604TRVJ", "name" : "PC-20160604TRVJ", "ip" : "192.168.1.33" } }
{ "_id" : ObjectId("584e010e5f519d1630e15736"), "timestamp" : ISODate("2016-12-12T01:44:46.630Z"), "level" : "INFO", "thread" : "DubboServerHandler-192.168.1.33:20882-thread-8", "message" : "UserInfoServiceImpl log", "loggerName" : { "fullyQualifiedClassName" : "MongoDB", "package" : [ "MongoDB" ], "className" : "MongoDB" }, "fileName" : "UserInfoServiceImpl.java", "method" : "testLog", "lineNumber" : "178", "class" : { "fullyQualifiedClassName" : "com.shanjin.mq.service.impl.UserInfoServiceImpl", "package" : [ "com", "shanjin", "mq", "service", "impl", "UserInfoServiceImpl" ], "className" : "UserInfoServiceImpl" }, "host" : { "process" : "5680@PC-20160604TRVJ", "name" : "PC-20160604TRVJ", "ip" : "192.168.1.33" } }
{ "_id" : ObjectId("584e1bb55f519d16cca462d2"), "timestamp" : ISODate("2016-12-12T03:38:29.642Z"), "level" : "INFO", "thread" : "qtp632707967-30", "message" : "mongodb log info", "loggerName" : { "fullyQualifiedClassName" : "MongoDB", "package" : [ "MongoDB" ], "className" : "MongoDB" }, "fileName" : "UserInfoController.java", "method" : "testLog", "lineNumber" : "155", "class" : { "fullyQualifiedClassName" : "com.shanjin.mq.controller.UserInfoController", "package" : [ "com", "shanjin", "mq", "controller", "UserInfoController" ], "className" : "UserInfoController" }, "host" : { "process" : "5836@PC-20160604TRVJ", "name" : "PC-20160604TRVJ", "ip" : "192.168.1.33" } }
{ "_id" : ObjectId("584e1bb55f519d16cca462d3"), "timestamp" : ISODate("2016-12-12T03:38:29.643Z"), "level" : "ERROR", "thread" : "qtp632707967-30", "message" : "mongodb log error", "loggerName" : { "fullyQualifiedClassName" : "MongoDB", "package" : [ "MongoDB" ], "className" : "MongoDB" }, "fileName" : "UserInfoController.java", "method" : "testLog", "lineNumber" : "156", "class" : { "fullyQualifiedClassName" : "com.shanjin.mq.controller.UserInfoController", "package" : [ "com", "shanjin", "mq", "controller", "UserInfoController" ], "className" : "UserInfoController" }, "host" : { "process" : "5836@PC-20160604TRVJ", "name" : "PC-20160604TRVJ", "ip" : "192.168.1.33" } }
{ "_id" : ObjectId("584e1bb55f519d1ca8b12503"), "timestamp" : ISODate("2016-12-12T03:38:29.647Z"), "level" : "INFO", "thread" : "DubboServerHandler-192.168.1.33:20882-thread-4", "message" : "用户身份核实通过", "loggerName" : { "fullyQualifiedClassName" : "MongoDB", "package" : [ "MongoDB" ], "className" : "MongoDB" }, "fileName" : "UserInfoServiceImpl.java", "method" : "testLog", "lineNumber" : "178", "class" : { "fullyQualifiedClassName" : "com.shanjin.mq.service.impl.UserInfoServiceImpl", "package" : [ "com", "shanjin", "mq", "service", "impl", "UserInfoServiceImpl" ], "className" : "UserInfoServiceImpl" }, "host" : { "process" : "7336@PC-20160604TRVJ", "name" : "PC-20160604TRVJ", "ip" : "192.168.1.33" } }
>
log4j+mongodb的更多相关文章
- 利用log4j+mongodb实现分布式系统中日志统一管理
背景 在分布式系统当中,我们有各种各样的WebService,这些服务可能分别部署在不同的服务器上,并且有各自的日志输出.为了方便对这些日志进行统一管理和分析.我们可以将日志统一输出到指定的数 ...
- log4j mongoDB配置
log4j.rootCategory=INFO, stdout log4j.appender.stdout=org.springframework.data.document.mongodb.log4 ...
- ycsb安装和使用介绍
nosql性能测试工具ycsb0.1的使用 使用文档参考地址:https://www.cnblogs.com/SailorXiao/p/5808828.html ycsb地址:https://gith ...
- log4j输出信息到mongodb
官网 http://log4mongo.org/display/PUB/Log4mongo+for+Java 保存主机信息,方法等 http://my.oschina.net/chi ...
- MongoDB log4j 日志整合
在分布式系统当中,这些服务可能分别部署在不同的服务器上,并且有各自的日志输出.为了方便对这些日志进行统一管理和分析.我们可以将日志统一输出到指定的数据库系统中,而再由日志分析系统去管理.而这个储存日志 ...
- log4j配置目标到mongodb
首先,具体采用什么技术作为集中式存储方案在99%的应用中应该来说并没有多大区别,最重要的是要定期清理不必要的日志,以及日志格式设计(也可以重写org.log4mongo.MongoDbPatternL ...
- Spring Boot log4j实现把日志存入mongodb
准备工作 1.自定义appender的实现 log4j提供的输出器实现自Appender接口,要自定义appender输出到MongoDB,只需要继承AppenderSkeleton类,并实现几个方法 ...
- Spring Boot中使用log4j实现http请求日志入mongodb
之前在<使用AOP统一处理Web请求日志>一文中介绍了如何使用AOP统一记录web请求日志.基本思路是通过aop去切web层的controller实现,获取每个http的内容并通过log4 ...
- apache log4j将日志保存在mongodb数据库中(转)
og4j与mongodb整合 Mongo Java driver jar包 log4mongo-java jar包 配置log4j.properties文件,使之整合mongodb: #将Mongod ...
随机推荐
- 利用Queue队列实现FIFO的算法
#!/usr/bin/env python # -*- coding: utf-8 -*- # learn <<Problem Solving with Algorithms and Da ...
- 不会全排列算法(Javascript实现),我教你呀!
今天我很郁闷,在实验室凑合睡了一晚,准备白天大干一场,结果一整天就只做出了一道算法题.看来还是经验不足呀,同志仍需努力呀. 算法题目要求是这样的: Return the number of total ...
- Linux 第06天
Linux 第06天 1.SAMBA服务器————(linux和windows的文件共享) 1.1 安装 yum install samba -yum 1.2 配置文件 /etc/samba/smb. ...
- IDF实验室:倒行逆施
简单的PE文件逆向(.exe-IDA) 下载下来文件之后发现是一个exe文件,运行以后发现.
- 浏览器-09 javascript引擎和Chromium网络栈
语言的运行 C/C++语言 使用编译器直接将它们编译成本地代码(机器指令),这是由开发人员在代码编写完成之后实施; 用户只是使用这些编译好的本地代码,这些本地代码被系统的加载器加载执行,由操作系统调度 ...
- 使用代理和block写一个alertView
代理: MyAlertView.h: @property (nonatomic,assign)id delegate; @protocol MyAlertViewDelegate <NSObje ...
- 关于MFi认证你所必须要知道的事情
MFiLogo 前面我写了一篇文章<iOS App连接外设的几种方式>,其中EAP和NCM是都需要做MFi认证.对于苹果的MFI认证,对iOS开发的同学来说其实是一个比较陌生并且繁琐的to ...
- Linux Tomcat 开机自启动的方法
修改Tomcat/bin/startup.sh 为: export JAVA_HOME=/usr/java/j2sdk1.4.2_08 export CLASSPATH=$CLASSPATH:$JAV ...
- 一个print的简单错误
原因是python 2.X 可以print 内容 而3.X 取消了这种写法 改成了print(内容)
- Spring3:AOP
AOP AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善.OOP引入 ...