cronolog安装配置

http://cronolog.org/

cronolog是一个比较不错的开源日志精细分割工具,这里简单介绍一下。更多详情请参考官方帮助文档。

以cronolog-1.6.2为例

一.下载:
wget http://cronolog.org/download/cronolog-1.6.2.tar.gz

root@localhost:~# wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
--2014-10-13 11:44:08--  http://cronolog.org/download/cronolog-1.6.2.tar.gz
Resolving cronolog.org... 85.119.82.138, 80.77.248.26
Connecting to cronolog.org|85.119.82.138|:80... failed: Connection refused.
Connecting to cronolog.org|80.77.248.26|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 133591 (130K) [application/x-gzip]
Saving to: “cronolog-1.6.2.tar.gz”

100%[======================================>] 133,591      116K/s   in 1.1s   

2014-10-13 11:44:10 (116 KB/s) - “cronolog-1.6.2.tar.gz” saved [133591/133591]


二.安装

yum -y install gcc gcc-c++  cmake automake autoconf  #编译时请先安装必备的编译工具包

[root@localhost ~]# tar -zxvf cronolog-1.6.2.tar.gz -C /usr/local/src/
[root@localhost ~]# cd /usr/local/src/cronolog-1.6.2/
[root@localhost cronolog-1.6.2]# ./configure && make && make install
[root@localhost ~]# crono
cronolog    cronosplit
安装完成后会生成两个命令 cronolog cronosplit


三.使用

以centos6.5 x64下的apache为例:/etc/httpd/conf/httpd.conf
示例:把错误日志格式及存放位置通过cronolog加以自定义,centos6标准的apache配置大约在484行
 478 # ErrorLog: The location of the error log file.
 479 # If you do not specify an ErrorLog directive within a
 480 # container, error messages relating to that virtual host will be
 481 # logged here.  If you *do* define an error logfile for a
 482 # container, that host's errors will be logged there and not here.
 483 #
  484 ErrorLog logs/error_log

 
 



以下是截取的官方说明:

Installation

Cronolog uses GNU autoconf, so it is configured and built with the standard sequence:

./configure
make

To install type "make install" or simply copy the executable "src/cronolog" to a suitable directory.

Cronolog has a number of options that can be set either by including in CFLAGS when configuring, or by editing the file "src/config.h":

  

-DFILE_MODE=octal-number   mode used for creating files (default is 0664)
-DDIR_MODE=octal-numbermode used for creating directories (default is 0775)
-DDONT_CREATE_SUBDIRSdon't include code to create missing directories
-DNEED_GETOPT_DEFSif your platform doesn't declare getopt()
e.g. to set the file mode to 0600:
CFLAGS="-O2 -DFILE_MODE=0600" ./configure

cronolog features

cronolog is a simple filter program that reads log file entries from standard input and writes each entry to the output file specified by a filename template and the current date and time. When the expanded filename changes, the current file is closed and a new one opened. cronolog is intended to be used in conjunction with a Web server, such as Apache, to split the access log into daily or monthly logs. For example the Apache configuration directives:
TransferLog "|/usr/sbin/cronolog /web/logs/%Y/%m/%d/access.log"

ErrorLog "|/usr/sbin/cronolog /web/logs/%Y/%m/%d/errors.log"
would instruct Apache to pipe its access and error log messages into separate copies of cronolog, which would create new log files each day in a directory hierarchy structured by date, i.e. on 31 December 2002 messages would be written to
/web/logs/2002/12/31/access.log
/web/logs/2002/12/31/errors.log
after midnight the files
/web/logs/2003/01/01/access.log
/web/logs/2003/01/01/errors.log
would be used, with the directories 2003, 2003/01 and 2003/01/01 being created if they did not already exist. More detail to come... Andrew Ford
2002-01-20

Cronolog usage

The cronolog package consists of two programs: cronolog and cronosplit. There is a manual page for each in PDF format ( cronolog and cronosplit)

The cronolog program

The cronolog program is normally invoked as a piped log filter program from Apache as specified in the configuration file. The direct program usage is:
/path/to/cronolog [OPTIONS] logfile-spec
The logfile-spec is a template that describes the names of the log files that should be written. Each character in the template represents a character in the expanded filename, except for date and time format specifiers, which are replaced by their expansion. Format specifiers consist of a " %" followed by a character as described in the table below. However it would normally be used in an Apache CustomLog directive as so:
CustomLog "|/path/to/cronolog [OPTIONS] logfile-spec" [format]
Note that the entire cronolog command line is enclosed within quotes and preceded by a vertical bar (" |"). The quotes cause Apache to regard the command line as a single argument and the presence of the vertical bar tells Apache that this is a piped log and that the command line is passed to the shell.

cronolog options

Long formShort formMeaning
--hardlink=NAME-H NAMEmaintain a hard link from NAME to the current log file
--symlink=NAME-S NAMEmaintain a symbolic link from NAME to the current log file
--prev-symlink=NAME  -P NAME maintain a symbolic link from NAME to previous log
--link=NAME-l NAMEsame as -S/--symlink
--help-hprint a help message then exit
--period=PERIOD -p PERIOD set the rotation period explicitly (new in 1.6.2)
--delay=DELAY set the rotation period delay (new in 1.6.2 -- this will be renamed --rotation-offset with a short form of -o in 1.6.3)
--once-only create single output log from template (not rotated)
--debug=FILE-x FILEwrite debug messages to FILE ( or to standard error if FILE is "-")
--american-aInterprete ambiguous start dates in American date formats (mm/dd/yy[yy])
--european-eInterprete ambiguous start dates in European date formats (dd/mm/yy[yy] - default)
--start-time=DT-s DTstarting date and time (in ambiguous cases interpreted according to --american or --european specification)
--time-zone=TZ-z TZuse TZ for timezone
--version-Vprint version number, then exit

Template specifiers

SpecifierDescription
%%a literal % character
%na new-line character
%ta horizontal tab character
Time fields
%Hhour (00..23)
%Ihour (01..12)
%pthe locale's AM or PM indicator
%Mminute (00..59)
%Ssecond (00..61, which allows for leap seconds)
%Xthe locale's time representation (e.g.: "15:12:47")
%Ztime zone (e.g. GMT), or nothing if the time zone cannot be determined
Date fields
%athe locale's abbreviated weekday name (e.g.: Sun..Sat)
%Athe locale's full weekday name (e.g.: Sunday .. Saturday)
%bthe locale's abbreviated month name (e.g.: Jan .. Dec)
%Bthe locale's full month name, (e.g.: January .. December)
%cthe locale's date and time (e.g.: "Sun Dec 15 14:12:47 GMT 1996")
%dday of month (01 .. 31)
%jday of year (001 .. 366)
%mmonth (01 .. 12)
%Uweek of the year with Sunday as first day of week (00..53, where week 1 is the week containing the first Sunday of the year)
%Wweek of the year with Monday as first day of week (00..53, where week 1 is the week containing the first Monday of the year)
%wday of week (0 .. 6, where 0 corresponds to Sunday)
%xlocale's date representation (e.g. today in Britain: "15/12/96")
%yyear without the century (00 .. 99)
%Yyear with the century (1970 .. 2038)

转载于:https://www.cnblogs.com/lixuebin/p/10814495.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值