E
- 数据类型public class RedisAppender<E>
extends ch.qos.logback.core.UnsynchronizedAppenderBase<E>
自定义日志输出器
该工具是logback日志里的一个自定义日志输出器,主要是利用redis的订阅发布功能, 将日志信息通过redis发布出来,以便其他终端能够接收到日志信息
使用方法如下:
<appender name="redis" class=com.yishuifengxiao.common.tool.log.RedisAppender">
<host>Redis服务器地址</host>
<port>Redis服务器端口号</port>
<password>redis连接密码</password>
<application>项目名字,可选,如 测试项目</application>
<channel>发送的订阅通道的名字,选填,默认为application的值</channel>
<extra>附加数据,会被加载在日志中</extra>
</appender>
Modifier and Type | Field and Description |
---|---|
protected ReentrantLock |
lock
All synchronization in this class is done via the lock object.
|
Constructor and Description |
---|
RedisAppender() |
Modifier and Type | Method and Description |
---|---|
protected void |
append(E eventObject) |
protected String |
application()
获取应用名字,如果应用名字为空就使用当前的主机名
|
protected String |
channel()
Redis 订阅通道名字
|
String |
getApplication()
获取应用名称
|
String |
getChannel()
获取Redis 订阅通道名字
|
String |
getExtra()
获取附加信息
|
String |
getHost()
设置Redis 数据库地址
|
String |
getPassword()
获取设置的 Redis 数据库密码
|
Integer |
getPort()
获取 Redis 数据库端口
|
Integer |
getTimeoutInSecond()
获取Redis 连接过期时间
|
protected int |
port()
获取连接的端口
|
void |
setApplication(String application)
设置 应用名称
|
void |
setChannel(String channel)
设置 Redis 订阅通道
|
void |
setExtra(String extra)
设置附加信息
|
void |
setHost(String host)
设置 Redis 数据库地址
|
void |
setPassword(String password)
设置 Redis 数据库密码,如果redis数据没有连接密码可以不用设置
|
void |
setPort(Integer port)
设置 Redis 数据库端口
|
void |
setTimeoutInSecond(Integer timeoutInSecond)
设置Redis 连接过期时间
|
void |
start() |
void |
stop() |
protected void |
subAppend(E event)
Actual writing occurs here.
|
protected int |
timeout()
获取连接的超时时间,单位为秒
|
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toString
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
protected final ReentrantLock lock
protected void append(E eventObject)
append
in class ch.qos.logback.core.UnsynchronizedAppenderBase<E>
protected int port()
protected int timeout()
protected String channel()
protected String application()
protected void subAppend(E event)
Most subclasses of WriterAppender
will need to override this
method.
event
- 日志事件public void start()
start
in interface ch.qos.logback.core.spi.LifeCycle
start
in class ch.qos.logback.core.UnsynchronizedAppenderBase<E>
public void stop()
stop
in interface ch.qos.logback.core.spi.LifeCycle
stop
in class ch.qos.logback.core.UnsynchronizedAppenderBase<E>
public String getHost()
public void setHost(String host)
host
- Redis 数据库地址public String getPassword()
public void setPassword(String password)
password
- Redis 数据库密码public Integer getPort()
public void setPort(Integer port)
port
- Redis 数据库端口,默认为6379public Integer getTimeoutInSecond()
public void setTimeoutInSecond(Integer timeoutInSecond)
timeoutInSecond
- Redis 连接过期时间,单位为秒public String getChannel()
public void setChannel(String channel)
channel
- Redis 订阅通道public String getApplication()
public void setApplication(String application)
application
- 应用名称public String getExtra()
public void setExtra(String extra)
extra
- 附加信息Copyright © 2021. All rights reserved.