MongoDB 做日志服务器
2023-09-14 08:59:51 时间
这样的日志与对懂shell,perl语言的人分析起来非常方便,对于程序员来说还是更喜欢写入数据库服务器,然后通过sql语句查询。
对于程序员来说sql语句提供了丰富查询功能,相比文本文件分析更容易。
下面就是一个简单日志表, 尽量做到通用所以只有message。
`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;
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:[13113668890,13322993040]}}) db.logging.user.save({asctime:2012-10-10 12:12:12,facility:sms,priority:error,operator:computer,message:send sms: 13113668890,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()
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" : [ 13113668890, 13322993040 ] } } { "_id" : ObjectId("50cc11a23e4f5a2b92fb5f39"), "asctime" : "2012-10-10 12:12:12", "facility" : "sms", "priority" : "error", "operator" : "computer", "message" : "send sms: 13113668890" } 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" }
netkiller Nickname:netkiller | English name: Neo chen | QQ: 291379 | 订阅号:netkiller-ebook | 网站:http://www.netkiller.cn
相关文章
- MongoDB 3.0的Explain
- java连接mongodb的一个奇葩问题及奇葩解决方式
- window上将MongoDB的启动加入到服务中
- 大数据应用之:MongoDB从入门到精通你不得不知的21个为什么?
- mongodb 备份与恢复
- java mongodb 基础系列---查询,排序,limit,$in,$or,输出为list,创建索引,$ne 非操作
- mongodb基础整理篇————聚合操作[三]
- mongodb基础整理篇————设计[四]
- MongoDB详解(五)——MongoDB数据库简单使用
- Docker安装部署MongoDB及MySql和MongoDB的语法对比
- MongoDB复制集自适应oplog管理
- 补习系列(17)-springboot mongodb 内嵌数据库
- 【MongoDB】Serveral common command of MongoDb
- 【MongoDB】在windows平台mongodb切片集群(三)
- mongodb的分布式集群(4、分片和副本集的结合)
- MongoDB(八)Mongodb——GridFS存储
- spring mongodb 复制集配置(实现读写分离)
- MongoDB 3.2复制集单节点部署(四)
- mongodb replica set 配置高性能多服务器详解
- MongoDB数据库安装部署及警告优化
- mongodb update