use of com.creditease.agent.log.api.ISystemLogger in project uavstack by uavorg.
the class OpenTSDBRestAgentServletCallBack method resp.
private void resp(HttpClientCallbackResult result) {
if (null != result.getException()) {
ISystemLogger logger = SystemLogger.getLogger(OpenTSDBRestAgentServletCallBack.class);
logger.err(this, result.getException().getMessage(), result.getException());
} else {
String respStr = result.getReplyDataAsString();
if (url.endsWith(".jpg") || url.endsWith(".png") || url.endsWith("&png")) {
downLoadImage(resp, url);
return;
}
try {
result.getResponseForRequestAsync().write(respStr.getBytes("UTF-8"));
result.getResponseForRequestAsync().flush();
result.getResponseForRequestAsync().close();
} catch (IOException e) {
ISystemLogger logger = SystemLogger.getLogger(OpenTSDBRestAgentServletCallBack.class);
logger.err(this, result.getException().getMessage(), result.getException());
}
}
}
use of com.creditease.agent.log.api.ISystemLogger in project uavstack by uavorg.
the class OpenTSDBRestAgentServletCallBack method downLoadImage.
private void downLoadImage(HttpServletResponse resp, String url) {
HttpClient client = new HttpClient();
GetMethod get = null;
try {
String path = url;
get = new GetMethod(path);
int i = client.executeMethod(get);
if (200 == i) {
resp.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode(path, "UTF-8"));
OutputStream out = null;
out = resp.getOutputStream();
out.write(get.getResponseBody());
out.flush();
out.close();
} else {
ISystemLogger logger = SystemLogger.getLogger(OpenTSDBRestAgentServletCallBack.class);
logger.err(this, "no pic");
}
} catch (Exception e) {
ISystemLogger logger = SystemLogger.getLogger(OpenTSDBRestAgentServletCallBack.class);
logger.err(this, e.getMessage());
} finally {
get.releaseConnection();
client.getHttpConnectionManager().closeIdleConnections(0);
}
}
use of com.creditease.agent.log.api.ISystemLogger in project uavstack by uavorg.
the class SystemLogger method newLogger.
private static ISystemLogger newLogger(String logName, String rootpath, String logFileFormat, String logLevel, Boolean debugEnable, int bufferSize, int fileSize, int fileCountLimit) {
ISystemLogger mainLog = new SystemLogger(logName, rootpath, logFileFormat, bufferSize, fileSize, fileCountLimit, false, new SimpleLogFormatter());
// set log level
if (null == logLevel) {
logLevel = "INFO";
}
mainLog.setLevel(LogLevel.valueOf(logLevel));
// set debug enable
if (null == debugEnable) {
debugEnable = false;
}
mainLog.enableDebug(debugEnable);
return mainLog;
}
use of com.creditease.agent.log.api.ISystemLogger in project uavstack by uavorg.
the class LineNumberWriter method writeLogToFile.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void writeLogToFile(Object... data) {
List<MonitorDataFrame> mdflist = (List<MonitorDataFrame>) data[0];
for (MonitorDataFrame mdf : mdflist) {
List<Map> instances = mdf.getElemInstances("com.creditease.uav.logProducer", "log");
for (Map instance : instances) {
String logFileName = (String) instance.get("id");
int mapIndex = obtainMapIndex(logFileName);
Map<String, Object> map = list.get(mapIndex);
if (map.isEmpty()) {
map.put("fileName", logFileName);
map.put("lineNum", 0);
}
File file = new File(logFileName);
ISystemLogger logger = null;
if (!logMap.containsKey(logFileName)) {
logger = SystemLogger.getTestlogger(file.getName() + "-logger", file.getName() + ".%g.%u.log", null, true, 100 * 1024 * 1024, 1);
logMap.put(logFileName, logger);
}
logger = logMap.get(logFileName);
Map valuesMap = (Map) instance.get("values");
String values = JSON.toJSONString(valuesMap);
JSONObject contentObeject = JSONObject.parseObject(values);
JSONArray array = contentObeject.getJSONArray("content");
int logLineNumber = 0;
for (int i = 0; i < array.size(); i++) {
JSONObject contentObejct = array.getJSONObject(i);
String content = contentObejct.getString("content");
logger.trace(this, content, true, data);
logLineNumber++;
}
map.put("lineNum", (int) map.get("lineNum") + logLineNumber);
}
}
}
use of com.creditease.agent.log.api.ISystemLogger in project uavstack by uavorg.
the class EsRestServletCallBack method resp.
private void resp(HttpClientCallbackResult result) {
if (null != result.getException()) {
ISystemLogger logger = SystemLogger.getLogger(EsRestServletCallBack.class);
logger.err(this, result.getException().getMessage(), result.getException());
} else {
String respStr = result.getReplyDataAsString();
try {
result.getResponseForRequestAsync().write(respStr.getBytes());
result.getResponseForRequestAsync().flush();
result.getResponseForRequestAsync().close();
} catch (IOException e) {
ISystemLogger logger = SystemLogger.getLogger(EsRestServletCallBack.class);
logger.err(this, result.getException().getMessage(), result.getException());
}
}
}
Aggregations