nxlog4go 按天或按文件大小分割日志
We always want to store the log recorder in file to analysis the program after running when developing.
nxlog4go includes an io.Writer which is similar to go log. So we can use io.MultiWriter.
Building a new rotate file writer
Setting output as MultiWriter
Write log to MultiWriter
+-----------------------------------------
| Format by pattern layout
| Write to console
| Write to file
| +---------------------------------------
| | Rotate file if over max size or daily
| | Real write
| +---------------------------------------
+-----------------------------------------
Close rotate file writer
The writer costs more CPU usage. Especially, it is expensive when using the caller function to get source's file name and line number as default. You may disable it by:
log.SetCaller(false)
Building a new rotate file writer
rfw := l4g.NewRotateFileWriter("_rfw.log").SetMaxSize(1024 * 5).SetMaxBackup(10)
Setting maxium file size as 5M, and keeping only 10 files.
Or:
rfw := l4g.NewRotateFileWriter("_rfw.log").SetDaily(true)
Rotating file every day at midnight.
Setting output as MultiWriter
Logging message to both term console and rotate file writer.
ww := io.MultiWriter(os.Stderr, rfw)
// Get a new logger instance
log := l4g.New(l4g.FINEST).SetOutput(ww).SetCaller(false)
log.SetPattern("[%D %T] [%L] (%s) %M\n")
Logging
log.Finest("Everything is created now (notice that I will not be printing to the file)")
log.Info("%d. The time is now: %s", j, time.Now().Format("15:04:05 MST 2006/01/02"))
log.Critical("Time to close out!")
CLOSING rotate file writer
Do not forget.
Call Close() function at the end of main program.
It is necessary to guarantee that all log messages are written.
rfw.Close()
Example
See also:
nxlog4go 按天或按文件大小分割日志的更多相关文章
- Log4j配置按照文件大小和日期分割日志文件
目录 Log4j 下载地址 文件大小分割日志文件 以日期分割每天产生一个日志文件 自定义信息输出到日志文件 Log4j 下载地址 Log4j是Apache的一个开源项目,通过使用Log4j,我们可以控 ...
- 实现golang io.Writer支持按照天为单位分割日志
golang中的日志不支持按照天分割,很多开源的日志包都是只支持按照文件大小分割日志,不太利于生产环境中的使用.因此我实现了timewriter,支持: 实现按照天为单位分割日志,可以完美支持gola ...
- Python 日志处理(一) 按Nginx log_format 分割日志记录
要求:不使用正则 根据nginx 默认的日志记录格式,分割日志记录. log_format main '$remote_addr - $remote_user [$time_local] " ...
- [Java][log4j]支持同一时候按日期和文件大小切割日志
依据DailyRollingFileAppender和RollingFileAppender改编,支持按日期和文件大小切割日志. 源文件: package com.bao.logging; impo ...
- nginx分割日志
实现nginx日志按照时间分割存储 backups_log.sh #设置log日志的存储地址 LOG_PATH=/home/soft/nginx/logs #设置历史日志的存储地址 HISTORY_L ...
- nginx按日分割日志
#!/bin/bash #按日切割nginx日志并压缩,加入crontab每天0:00切割 #作者:fafu_li #时间: source /etc/profile #加载系统环境变量 source ...
- 使用cronolog按日期分割日志
cronologcronolog是一个简单的过滤程序从标准输入读取日志文件条目,每个条目写入到输出文件指定一个文件名模板和当前的日期和时间.当扩大的文件名更改,关闭当前文件,并打开一个新的. cron ...
- log4net 既要按日期分割日志文件,又要按文件大小分割。
<appender name="DebugAppender" type="log4net.Appender.RollingFileAppender"> ...
- apache 访问日志access_log 配置和解析 rotatelogs分割日志
一.解析访问日志 apache 的访问日志记载着大量的信息,学会高效快捷的读出其中关键信息对我们的工作有极大帮助. 如果Apache的安装方式是默认安装,服务器一运行就会有两 ...
随机推荐
- 在Word2010文档中显示域代码而非域值
当Word2010文档中含有域内容时,默认情况下显示域值,这样可以使插入的域内容清晰明了.用户可以根据需要选择显示域代码或显示域值,操作步骤如下所述: 步骤/方法 第1步,打开Word2010文档窗口 ...
- arduino与DS1302时钟调试失败的分析
前两天测试了时钟模块,但是,一直失败,能读取时间,但是设置不了时间,所以.这次我查了很多资料,发现好像是信号线的问题,线太长,数据收到干扰, 资料如下http://www.51hei.com/bbs/ ...
- 流API--流的收集
前面的一系列博客中,我们都是从一个集合中拿到一个流,但是有时候需要执行反操作,就是从流中获得集合.实际编码中,当我们处理完流后,我们通常想查看下结果,而不是将他们聚合成一个值.我们可以调用iterat ...
- hadoop - spark on yarn 集群搭建
一.环境准备 1. 机器: 3 台虚拟机 机器 角色 l-qta3.sp.beta.cn0 NameNode,ResourceManager,spark的master l-querydiff1.sp ...
- linux判断文件是否存在
#!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" # 这里的-x 参 ...
- 浅析调用JSR303的validate方法, 验证失败时抛出ConstraintViolationException
废话不多说,直接进入正题:如何使用JSR303的validate,进行数据校验,失败后直接抛出异常加入流转信息中,并在form页面提示出来. 首先我们为了启用验证,需要向 项目中添加Bean验证的实现 ...
- Spring常用注解简析
1. Autowired 自动装配,其作用是为了消除代码Java代码里面的getter/setter与bean属性中的property.当然,getter看个人需求,如果私有属性需要对外提供的话,应当 ...
- SQL性能优化的几点建议
1. 索引:索引可以提高查询的速度,但不是使用带有索引的字段查询时,索引都会起作用,如下几种特殊情况下,有可能使用带有索引的字段查询时,索引没有起作用:1)使用LIKE关键字的查询语句 如果匹配字符串 ...
- CentOS 7.1静默安装11.2.0.3 64位单机数据库软件
第1章 CentOS 7.1静默安装11.2.0.3 64位单机数据库软件 1.1 安装前的准备工作 1.1.1 软件准备 1.1.2 检查硬件 注意这里的内存应该满足要求,不然 ...
- Spring-shiro源码陶冶-DefaultFilter
阅读源码有助于陶冶情操,本文旨在简单的分析shiro在Spring中的使用 简单介绍 Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能 Apache Shiro自带的 ...