最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

MongoDB做日志服务器

来源:动视网 责编:小采 时间:2020-11-09 16:21:15
文档

MongoDB做日志服务器

MongoDB做日志服务器:MongoDB做日志服务器 MongoDB 做日志服务器。 www.2cto.com 写日志最常用的方式是写入纯文本文件,然后安日期分割文件,压错旧文件。 这样的日志与对懂shell,perl语言的人分析起来非常方便,对于程序员来说还是更喜欢写入数据库服务器,然后通过sql语句查
推荐度:
导读MongoDB做日志服务器:MongoDB做日志服务器 MongoDB 做日志服务器。 www.2cto.com 写日志最常用的方式是写入纯文本文件,然后安日期分割文件,压错旧文件。 这样的日志与对懂shell,perl语言的人分析起来非常方便,对于程序员来说还是更喜欢写入数据库服务器,然后通过sql语句查


MongoDB做日志服务器 MongoDB 做日志服务器。 www.2cto.com 写日志最常用的方式是写入纯文本文件,然后安日期分割文件,压错旧文件。 这样的日志与对懂shell,perl语言的人分析起来非常方便,对于程序员来说还是更喜欢写入数据库服务器,然后通过sql语句查询

MongoDB做日志服务器

MongoDB 做日志服务器。

www.2cto.com

写日志最常用的方式是写入纯文本文件,然后安日期分割文件,压错旧文件。

这样的日志与对懂shell,perl语言的人分析起来非常方便,对于程序员来说还是更喜欢写入数据库服务器,然后通过sql语句查询。

对于程序员来说sql语句提供了丰富查询功能,相比文本文件分析更容易。

下面就是一个简单日志表, 尽量做到通用所以只有message。

Sql代码

CREATE TABLE `logging` (

`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,

`tag` ENUM('unknow','user','bbs','cart','admin') NOT NULL DEFAULT 'unknow' COMMENT '日志标签域',

`asctime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '产生时间',

`facility` ENUM('unknow','account','bank','unionpay','sms','email','register') NOT NULL DEFAULT 'unknow' COMMENT '类别',

`priority` ENUM('info','warning','error','critical','exception','debug') NOT NULL DEFAULT 'debug' COMMENT '级别',

`message` VARCHAR(512) NOT NULL COMMENT '内容',

`operator` VARCHAR(50) NOT NULL DEFAULT 'computer' COMMENT '操作者',

PRIMARY KEY (`id`)

)

COMMENT='日志表'

COLLATE='utf8_general_ci'

ENGINE=InnoDB;

www.2cto.com

mongodb 的message字段比起sql更灵活

Java代码

db.logging.user.save({'asctime':'2012-10-10 12:12:12','facility':'register','priority':'info','operator':'computer','message':{'name':'neo','address':{'city':'shenzhen','post':518000},'phone':[131136680,13322993040]}})

db.logging.user.save({'asctime':'2012-10-10 12:12:12','facility':'sms','priority':'error','operator':'computer','message':'send sms: 131136680,text: xxxxx'})

db.logging.user.find()

db.logging.admin.save({'asctime':'2012-10-10 12:12:12','facility':'account','priority':'info','operator':'computer','message':'delete account'})

db.logging.admin.save({'asctime':'2012-10-10 12:12:12','facility':'sms','priority':'info','operator':'computer','message':'send sms'})

db.logging.admin.save({'asctime':'2012-10-10 12:12:12','facility':'bank','priority':'warning','operator':'computer','message':'bank from xxxx to xxxx'})

db.logging.admin.find()

Java代码

> db.logging.user.find()

{ "_id" : ObjectId("50cc10dd3e4f5a2b92fb5f37"), "asctime" : "2012-10-10 12:12:12", "facility" : "register", "priority" : "info", "operator" : "computer", "message" : { "name" : "neo", "address" : { "city" : "shenzhen", "post" : 518000 }, "phone" : [ 131136680, 13322993040 ] } }

{ "_id" : ObjectId("50cc11a23e4f5a2b92fb5f39"), "asctime" : "2012-10-10 12:12:12", "facility" : "sms", "priority" : "error", "operator" : "computer", "message" : "send sms: 131136680" }

> db.logging.admin.find()

{ "_id" : ObjectId("50cc11443e4f5a2b92fb5f38"), "asctime" : "2012-10-10 12:12:12", "facility" : "account", "priority" : "info", "operator" : "computer", "message" : "delete account" }

{ "_id" : ObjectId("50cc120c3e4f5a2b92fb5f3a"), "asctime" : "2012-10-10 12:12:12", "facility" : "bank", "priority" : "warning", "operator" : "computer", "message" : "bank from xxxx to xxxx" }

>

文档

MongoDB做日志服务器

MongoDB做日志服务器:MongoDB做日志服务器 MongoDB 做日志服务器。 www.2cto.com 写日志最常用的方式是写入纯文本文件,然后安日期分割文件,压错旧文件。 这样的日志与对懂shell,perl语言的人分析起来非常方便,对于程序员来说还是更喜欢写入数据库服务器,然后通过sql语句查
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top