Elastic...

Elasticsearch搭建和日志配置

2019-01-16  本文已影响0人  平头哥2

Elasticsearch

一、搭建Elasticsearch

二、配置Elasticsearch

##1. 配置RollingFile appender 
appender.rolling.type = RollingFile 
appender.rolling.name = rolling
##2.Log to /日志路径/集群名字.log 
appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log 
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %.-10000m%n
##3. 将日志滚动到/日志路径/集群名字-yyyy-MM-dd-i.log;日志将在每个卷上压缩, i递增
appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log.gz 
appender.rolling.policies.type = Policies
#4. 使用基于时间的滚动策略
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy 
#5. 每天滚动日志
appender.rolling.policies.time.interval = 1 
#6.按照自然天计算(而不是每隔二十四小时滚动)
appender.rolling.policies.time.modulate = true 
#7. 使用基于大小的滚动策略
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy 
#8. 256 MB后滚动日志
appender.rolling.policies.size.size = 256MB 
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.fileIndex = nomax
#9. 滚动日志时使用删除操作
appender.rolling.strategy.action.type = Delete 
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
#10. 仅删除与文件模式匹配的日志
appender.rolling.strategy.action.condition.type = IfFileName 
#11. 该模式仅删除主日志
appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* 
#12. 仅在我们累积了太多压缩日志时才删除
appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize 
#13. 压缩日志的大小条件为2 GB
appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB

注意: Log4j的配置解析被任何无关的空格弄糊涂了; 如果您在此页面上复制并粘贴任何Log4j设置,或者一般输入任何Log4j配置,请务必修剪任何前导和尾随空格。

注意,您可以在appender.rolling.filePattern中使用.zip替换.gz,以使用zip格式压缩滚动日志。 如果删除.gz扩展名,则日志将不会在滚动时进行压缩。

如果要在指定的时间段内保留日志文件,可以使用具有删除操作的翻转策略。

配置如下:

#1. Configure the DefaultRolloverStrategy 
appender.rolling.strategy.type = DefaultRolloverStrategy 
#2. Configure the Delete action for handling rollovers 
appender.rolling.strategy.action.type = Delete 
#3. The base path to the Elasticsearch logs 
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path} 
#4. The condition to apply when handling rollovers 
appender.rolling.strategy.action.condition.type = IfFileName 
#5. Delete files from the base path matching the glob ${sys:es.logs.cluster_name}-*; this is the glob that log files are rolled to; this is needed to only delete the rolled Elasticsearch logs but not also delete the deprecation and slow logs 
appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* 
#6. A nested condition to apply to files matching the glob 
appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified 
#7. Retain logs for seven days 
appender.rolling.strategy.action.condition.nested_condition.age = 7D 

更多的配置请参考:http://logging.apache.org/log4j/2.x/manual/configuration.html

通过 log4j2.properties 配置日志级别:

logger.<unique_identifier>.name = <name of logging hierarchy>
logger.<unique_identifier>.level = <level>

例如:

logger.transport.name = org.elasticsearch.transport
logger.transport.level = trace
上一篇 下一篇

猜你喜欢

热点阅读