Last active
January 19, 2017 05:48
-
-
Save clarkzjw/7e90db7e7e131b4a9e2d79d0d9307e46 to your computer and use it in GitHub Desktop.
LogStash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import time | |
from logging.handlers import RotatingFileHandler | |
# ---------------------------------------------------------------------- | |
def create_rotating_log(path): | |
""" | |
Creates a rotating log | |
""" | |
logger = logging.getLogger("Rotating Log") | |
logger.setLevel(logging.INFO) | |
# add a rotating handler | |
handler = RotatingFileHandler(path, maxBytes=100, | |
backupCount=5) | |
logger.addHandler(handler) | |
for i in range(1, 100): | |
logger.info("This is test log line %s" % i) | |
print("This is test log line %s" % i) | |
time.sleep(1) | |
# ---------------------------------------------------------------------- | |
if __name__ == "__main__": | |
log_file = "test.log" | |
create_rotating_log(log_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input { | |
file{ | |
# Path 根据应用的实际情况来填 | |
path => ["/home/clarkzjw/Tomcat/python/test.log.*", "/home/clarkzjw/Tomcat/python/test.log"] | |
# discover_interval尽量设置小一点,单位是秒,作用是发现新的Log文件的周期 | |
discover_interval => 1 | |
start_position => "beginning" | |
sincedb_path => "/home/clarkzjw/Tomcat/python/sincedb" | |
} | |
# 如果以Filebeat作为输入 | |
# beats { | |
# port => 5044 | |
# } | |
} | |
output { | |
# 这里把读取到的Log输出到stdout,也可对接ELK等方案 | |
stdout{ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment