读取尚未读取的日志文件行。
pygtail的Python项目详细描述
python的logcheck’s logtail2端口。
pygtail读取尚未读取的日志文件行。它甚至会 处理已旋转的日志文件。
用法
从命令行:
Usage: pygtail.py [options] logfile Print log file lines that have not been read. Options: -h, --help show this help message and exit -o OFFSET_FILE, --offset-file=OFFSET_FILE File to which offset data is written (default: <logfile>.offset). -p, --paranoid Update the offset file every time we read a line (as opposed to only when we reach the end of the file). -n N, --every-n=N Update the offset file every N'th time we read a line (as opposed to only when we reach the end of the file). --no-copytruncate Don't support copytruncate-style log rotation. Instead, if the log file shrinks, print a warning. --read-from-end Read log file from the end if offset file is missing. Useful for large files. --log-pattern Custom log rotation glob pattern. Use %s to represent the original filename. You may use this multiple times to provide multiple patterns. --full_lines Only log when line ends in a newline `\n` (default: False) --version Print version and exit.
在您的代码中:
frompygtailimportPygtailforlineinPygtail("some.log"):sys.stdout.write(line)
贡献
拉取请求非常受欢迎,但如果您不包括测试,我不会合并您的更改。使用python setup.py test运行测试。