一、針對每一個類裏都定義一個logger顯得繁瑣,能夠定義一個LogUtil,將做用類似的某些類劃分紅一個log,例如notify package中有notifyTask、notifyProcessor、notifyService,能夠歸爲java
static public final Logger notifyLog = LoggerFactory.getLogger("com.taobao.diamond.server.notifyLog");
LogUtil結構以下,每一個log能夠設置成一個log文件,利用logback.xml配置app
public class LogUtil { /** * 默認的日誌 */ static public final Logger defaultLog = LoggerFactory.getLogger("com.taobao.diamond.server"); /** * 致命錯誤,須要告警 */ static public final Logger fatalLog = LoggerFactory .getLogger("com.taobao.diamond.server.fatal"); ...... }
<logger name="com.taobao.diamond.server.fatal" additivity="false"> <level value="INFO" /> <appender-ref ref="fatalFile" /> </logger> <appender name="fatalFile" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${user.home}/diamond/logs/fatal.log</file> <append>true</append> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <fileNamePattern>${user.home}/diamond/logs/fatal.log.%d{yyyy-MM-dd}.%i</fileNamePattern> <maxFileSize>20MB</maxFileSize> <MaxHistory>15</MaxHistory> <totalSizeCap>128MB</totalSizeCap> <cleanHistoryOnStart>true</cleanHistoryOnStart> </rollingPolicy> <encoder> <Pattern>%date %level %msg%n%n</Pattern> <charset>GBK</charset> </encoder> </appender>
二、Properties文件包含衆多kv,定義一個PropertyUtil,由它負責解析出每一個kv,再使用函數返回v。一樣系統參數如System.getProperty("diamond.server.port", "8080");也能夠使用這種方式。函數
notifySocketTimeout = Integer.valueOf(props.getProperty("notifySocketTimeout", "200")); public static int getNotifySocketTimeout() {return notifySocketTimeout;}