📄 gscdiag.java
字号:
package com.tianxun.NEI.sniffer.util;
/**
* The GscDiag write the diagnosis message to a log file, because it does a lot of
* I/O operation, it will effect the performance of process.
*/
public class GscDiag {
/** */
private static Logger logger;
/**
* Initializes Diagnosis facility.
*
* @param logger operation logger
*/
public static synchronized void initialize(Logger logger) {
GscDiag.logger = logger;
}
/**
* Initializes Diagnosis facility.
* set the Logfile name ,loglevel and logdir
*
* @param logdir save log directory
* @param logName log file name
* @param logLevel log level
*/
public static synchronized void initialize(String logdir,
String logName,
int logLevel) {
logger = new Logger(logdir, logName, logLevel);
logger.writeConfigurations();
}
/**
* Initializes Diagnosis facility.
* set the Logfile name and loglevel
* the logfile directory is under system temp directory
*
* @param logName log file name
* @param logLevel log level
*/
public static synchronized void initialize(String logName, int logLevel) {
logger = new Logger(logName, logLevel);
logger.writeConfigurations();
}
/**
* Initializes Diagnosis facility.
* set the Logfile name and loglevel
* the logfile directory is under system temp directory
*
* @param logName log file name
*/
public static synchronized void initialize(String logName) {
logger = new Logger(logName);
logger.writeConfigurations();
}
/**
* Initializes Diagnosis facility.
* use default logname ="GscDiag" and loglevel=3
*/
public static synchronized void initialize() {
logger = new Logger("GscDiag");
logger.writeConfigurations();
}
public static synchronized String getLogName() {
return logger == null ? "GscDiag" : logger.getLogName();
}
public static synchronized int getLogLevel() {
return logger == null ? Logger.SANITY_LEVEL : logger.getLogLevel();
}
public static synchronized String getLogDir() {
return logger == null ? null : logger.getLogDir();
}
/**
* Shuts down Diagnosis facility.
*/
public static synchronized void shutDown() {
if (logger != null) {
logger.shutDown();
}
}
/**
* Logs this message.
*
* @param logLevel log level that controls if this message will be logged.
* When this log level is equal or greater than the defined log level, this message is logged.
* @param title text title to be put into the log.
* @param message text message to be logged.
*/
public static synchronized void log(
int logLevel, String title, String message) {
if (logger == null) {
initialize();
}
logger.log(logLevel, title, message);
}
/**
* Logs this message.
*
* @param logLevel log level that controls if this message will be logged.
* When this log level is equal or greater than the definedlog level, this message is logged.
* @param message text message to be logged.
*/
public static synchronized void log(int logLevel, String message) {
if (logger == null) {
initialize();
}
logger.log(logLevel, message);
}
/** Logs the stack trace of an exception.
*
* @param logLevel log level that controls if this message will be logged.
* When this log level is equal or greater than the defined log level, this message is logged.
* @param title text title to be put into the log.
* @param throwable exception to be logged.
*/
public static synchronized void printStackTrace(
int logLevel, String title, Throwable throwable) {
if (logger == null) {
initialize();
}
logger.printStackTrace(logLevel, title, throwable);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -