Search in sources :

Example 1 with ISystemLogger

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());
        }
    }
}
Also used : ISystemLogger(com.creditease.agent.log.api.ISystemLogger) IOException(java.io.IOException)

Example 2 with ISystemLogger

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);
    }
}
Also used : ISystemLogger(com.creditease.agent.log.api.ISystemLogger) HttpClient(org.apache.commons.httpclient.HttpClient) OutputStream(java.io.OutputStream) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 3 with ISystemLogger

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;
}
Also used : ISystemLogger(com.creditease.agent.log.api.ISystemLogger) ISystemLogger(com.creditease.agent.log.api.ISystemLogger) SimpleLogFormatter(com.creditease.agent.log.PLogger.SimpleLogFormatter)

Example 4 with ISystemLogger

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);
        }
    }
}
Also used : ISystemLogger(com.creditease.agent.log.api.ISystemLogger) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(com.alibaba.fastjson.JSONObject) MonitorDataFrame(com.creditease.agent.monitor.api.MonitorDataFrame) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Example 5 with ISystemLogger

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());
        }
    }
}
Also used : ISystemLogger(com.creditease.agent.log.api.ISystemLogger) IOException(java.io.IOException)

Aggregations

ISystemLogger (com.creditease.agent.log.api.ISystemLogger)5 IOException (java.io.IOException)3 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 SimpleLogFormatter (com.creditease.agent.log.PLogger.SimpleLogFormatter)1 MonitorDataFrame (com.creditease.agent.monitor.api.MonitorDataFrame)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1