Java Code Examples for com.alibaba.dubbo.common.logger.LoggerFactory#getFile()

The following examples show how to use com.alibaba.dubbo.common.logger.LoggerFactory#getFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Logs.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void index(Map<String, Object> context) throws Exception {
    long size;
    String content;
    String modified;
    File file = LoggerFactory.getFile();
    if (file != null && file.exists()) {
        FileInputStream fis = new FileInputStream(file);
        FileChannel channel = fis.getChannel();
        size = channel.size();
        ByteBuffer bb;
        if (size <= SHOW_LOG_LENGTH) {
            bb = ByteBuffer.allocate((int) size);
            channel.read(bb, 0);
        } else {
            int pos = (int) (size - SHOW_LOG_LENGTH);
            bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
            channel.read(bb, pos);
        }
        bb.flip();
        content = new String(bb.array()).replace("<", "&lt;").replace(">", "&gt;");
        modified = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(file.lastModified()));
    } else {
        size = 0;
        content = "";
        modified = "Not exist";
    }
    Level level = LoggerFactory.getLevel();
    context.put("name", file == null ? "" : file.getAbsoluteFile());
    context.put("size", String.valueOf(size));
    context.put("level", level == null ? "" : level);
    context.put("modified", modified);
    context.put("content", content);
}
 
Example 2
Source File: LogsController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("")
public String index(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
    prepare(request, response, model, "index", "logs");
    long size;
    String content;
    String modified;
    File file = LoggerFactory.getFile();
    if (file != null && file.exists()) {
        FileInputStream fis = new FileInputStream(file);
        FileChannel channel = fis.getChannel();
        size = channel.size();
        ByteBuffer bb;
        if (size <= SHOW_LOG_LENGTH) {
            bb = ByteBuffer.allocate((int) size);
            channel.read(bb, 0);
        } else {
            int pos = (int) (size - SHOW_LOG_LENGTH);
            bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
            channel.read(bb, pos);
        }
        bb.flip();
        content = new String(bb.array()).replace("<", "&lt;").replace(">", "&gt;");
        modified = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(file.lastModified()));
    } else {
        size = 0;
        content = "";
        modified = "Not exist";
    }
    Level level = LoggerFactory.getLevel();
    model.addAttribute("name", file == null ? "" : file.getAbsoluteFile());
    model.addAttribute("size", String.valueOf(size));
    model.addAttribute("level", level == null ? "" : level);
    model.addAttribute("modified", modified);
    model.addAttribute("content", content);
    return "sysinfo/screen/logs/index";
}
 
Example 3
Source File: Logs.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void index(Map<String, Object> context) throws Exception {
    long size;
    String content;
    String modified;
    File file = LoggerFactory.getFile();
    if (file != null && file.exists()) {
        FileInputStream fis = new FileInputStream(file);
        FileChannel channel = fis.getChannel();
        size = channel.size();
        ByteBuffer bb;
        if (size <= SHOW_LOG_LENGTH) {
            bb = ByteBuffer.allocate((int) size);
            channel.read(bb, 0);
        } else {
            int pos = (int) (size - SHOW_LOG_LENGTH);
            bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
            channel.read(bb, pos);
        }
        bb.flip();
        content = new String(bb.array()).replace("<", "&lt;").replace(">", "&gt;");
        modified = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(file.lastModified()));
    } else {
        size = 0;
        content = "";
        modified = "Not exist";
    }
    Level level = LoggerFactory.getLevel();
    context.put("name", file == null ? "" : file.getAbsoluteFile());
    context.put("size", String.valueOf(size));
    context.put("level", level == null ? "" : level);
    context.put("modified", modified);
    context.put("content", content);
}
 
Example 4
Source File: Logs.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void index(Map<String, Object> context) throws Exception {
    long size;
    String content;
    String modified;
    File file = LoggerFactory.getFile();
    if (file != null && file.exists()) {
        FileInputStream fis = new FileInputStream(file);
        FileChannel channel = fis.getChannel();
        size = channel.size();
        ByteBuffer bb;
        if (size <= SHOW_LOG_LENGTH) {
            bb = ByteBuffer.allocate((int) size);
            channel.read(bb, 0);
        } else {
            int pos = (int) (size - SHOW_LOG_LENGTH);
            bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
            channel.read(bb, pos);
        }
        bb.flip();
        content = new String(bb.array()).replace("<", "&lt;").replace(">", "&gt;");
        modified = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(file.lastModified()));
    } else {
        size = 0;
        content = "";
        modified = "Not exist";
    }
    Level level = LoggerFactory.getLevel();
    context.put("name", file == null ? "" : file.getAbsoluteFile());
    context.put("size", String.valueOf(size));
    context.put("level", level == null ? "" : level);
    context.put("modified", modified);
    context.put("content", content);
}
 
Example 5
Source File: Logs.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public void index(Map<String, Object> context) throws Exception {
    long size;
    String content;
    String modified;
    File file = LoggerFactory.getFile();
    if (file != null && file.exists()) {
        FileInputStream fis = new FileInputStream(file);
        FileChannel channel = fis.getChannel();
        size = channel.size();
        ByteBuffer bb;
        if (size <= SHOW_LOG_LENGTH) {
            bb = ByteBuffer.allocate((int) size);
            channel.read(bb, 0);
        } else {
            int pos = (int) (size - SHOW_LOG_LENGTH);
            bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
            channel.read(bb, pos);
        }
        bb.flip();
        content = new String(bb.array()).replace("<", "&lt;").replace(">", "&gt;");
        modified = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(file.lastModified()));
    } else {
        size = 0;
        content = "";
        modified = "Not exist";
    }
    Level level = LoggerFactory.getLevel();
    context.put("name", file == null ? "" : file.getAbsoluteFile());
    context.put("size", String.valueOf(size));
    context.put("level", level == null ? "" : level);
    context.put("modified", modified);
    context.put("content", content);
}
 
Example 6
Source File: Logs.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public void index(Map<String, Object> context) throws Exception {
    long size;
    String content;
    String modified;
    File file = LoggerFactory.getFile();
    if (file != null && file.exists()) {
        FileInputStream fis = new FileInputStream(file);
        FileChannel channel = fis.getChannel();
        size = channel.size();
        ByteBuffer bb;
        if (size <= SHOW_LOG_LENGTH) {
            bb = ByteBuffer.allocate((int) size);
            channel.read(bb, 0);
        } else {
            int pos = (int) (size - SHOW_LOG_LENGTH);
            bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
            channel.read(bb, pos);
        }
        bb.flip();
        content = new String(bb.array()).replace("<", "&lt;").replace(">", "&gt;");
        modified = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(file.lastModified()));
    } else {
        size = 0;
        content = "";
        modified = "Not exist";
    }
    Level level = LoggerFactory.getLevel();
    context.put("name", file == null ? "" : file.getAbsoluteFile());
    context.put("size", String.valueOf(size));
    context.put("level", level == null ? "" : level);
    context.put("modified", modified);
    context.put("content", content);
}
 
Example 7
Source File: LogTelnetHandler.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
public String telnet(Channel channel, String message) {
    long size = 0;
    File file = LoggerFactory.getFile();
    StringBuilder buf = new StringBuilder();
    if (message == null || message.trim().length() == 0) {
        buf.append("EXAMPLE: log error / log 100");
    } else {
        String str[] = message.split(" ");
        if (!StringUtils.isInteger(str[0])) {
            LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
        } else {
            int SHOW_LOG_LENGTH = Integer.parseInt(str[0]);

            if (file != null && file.exists()) {
                try {
                    try (FileInputStream fis = new FileInputStream(file)) {
                        try (FileChannel filechannel = fis.getChannel()) {
                            size = filechannel.size();
                            ByteBuffer bb;
                            if (size <= SHOW_LOG_LENGTH) {
                                bb = ByteBuffer.allocate((int) size);
                                filechannel.read(bb, 0);
                            } else {
                                int pos = (int) (size - SHOW_LOG_LENGTH);
                                bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
                                filechannel.read(bb, pos);
                            }
                            bb.flip();
                            String content = new String(bb.array()).replace("<", "&lt;")
                                    .replace(">", "&gt;").replace("\n", "<br/><br/>");
                            buf.append("\r\ncontent:" + content);

                            buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                                    .format(new Date(file.lastModified()))));
                            buf.append("\r\nsize:" + size + "\r\n");
                        }
                    }
                } catch (Exception e) {
                    buf.append(e.getMessage());
                }
            } else {
                size = 0;
                buf.append("\r\nMESSAGE: log file not exists or log appender is console .");
            }
        }
    }
    buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel())
            .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath()));
    return buf.toString();
}
 
Example 8
Source File: LogTelnetHandler.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public String telnet(Channel channel, String message) {
    long size = 0 ;
    File file = LoggerFactory.getFile();
    StringBuffer buf = new StringBuffer();
    if (message == null || message.trim().length() == 0) {
        buf.append("EXAMPLE: log error / log 100");
    }else {
        String str[] = message.split(" ");
        if (! StringUtils.isInteger(str[0])){
            LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
        } else {
            int SHOW_LOG_LENGTH = Integer.parseInt(str[0]);
            
            if (file != null && file.exists()) {
                try{
                    FileInputStream fis = new FileInputStream(file);
                    FileChannel filechannel = fis.getChannel();
                    size = filechannel.size();
                    ByteBuffer bb;
                    if (size <= SHOW_LOG_LENGTH) {
                        bb = ByteBuffer.allocate((int) size);
                        filechannel.read(bb, 0);
                    } else {
                        int pos = (int) (size - SHOW_LOG_LENGTH);
                        bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
                        filechannel.read(bb, pos);
                    }
                    bb.flip();
                    String content = new String(bb.array()).replace("<", "&lt;")
                    .replace(">", "&gt;").replace("\n", "<br/><br/>");
                    buf.append("\r\ncontent:"+content);
                    
                    buf.append("\r\nmodified:"+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                    .format(new Date(file.lastModified()))));
                    buf.append("\r\nsize:"+size +"\r\n");
                }catch (Exception e) {
                    buf.append(e.getMessage());
                }
            }else {
                size = 0;
                buf.append("\r\nMESSAGE: log file not exists or log appender is console .");
            }
        }
    }
    buf.append("\r\nCURRENT LOG LEVEL:"+ LoggerFactory.getLevel())
    .append("\r\nCURRENT LOG APPENDER:"+ (file == null ? "console" : file.getAbsolutePath()));
    return buf.toString();
}
 
Example 9
Source File: LogTelnetHandler.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public String telnet(Channel channel, String message) {
    long size = 0 ;
    File file = LoggerFactory.getFile();
    StringBuffer buf = new StringBuffer();
    if (message == null || message.trim().length() == 0) {
        buf.append("EXAMPLE: log error / log 100");
    }else {
        String str[] = message.split(" ");
        if (! StringUtils.isInteger(str[0])){
            LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
        } else {
            int SHOW_LOG_LENGTH = Integer.parseInt(str[0]);
            
            if (file != null && file.exists()) {
                try{
                    FileInputStream fis = new FileInputStream(file);
                    try {
                     FileChannel filechannel = fis.getChannel();
                     try {
                      size = filechannel.size();
                      ByteBuffer bb;
                      if (size <= SHOW_LOG_LENGTH) {
                          bb = ByteBuffer.allocate((int) size);
                          filechannel.read(bb, 0);
                      } else {
                          int pos = (int) (size - SHOW_LOG_LENGTH);
                          bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
                          filechannel.read(bb, pos);
                      }
                      bb.flip();
                      String content = new String(bb.array()).replace("<", "&lt;")
                      .replace(">", "&gt;").replace("\n", "<br/><br/>");
                      buf.append("\r\ncontent:"+content);
                      
                      buf.append("\r\nmodified:"+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                      .format(new Date(file.lastModified()))));
                      buf.append("\r\nsize:"+size +"\r\n");
                     } finally {
                     	filechannel.close();
                     }
                    } finally {
                    	fis.close();
                    }
                }catch (Exception e) {
                    buf.append(e.getMessage());
                }
            }else {
                size = 0;
                buf.append("\r\nMESSAGE: log file not exists or log appender is console .");
            }
        }
    }
    buf.append("\r\nCURRENT LOG LEVEL:"+ LoggerFactory.getLevel())
    .append("\r\nCURRENT LOG APPENDER:"+ (file == null ? "console" : file.getAbsolutePath()));
    return buf.toString();
}
 
Example 10
Source File: LogTelnetHandler.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public String telnet(Channel channel, String message) {
    long size = 0 ;
    File file = LoggerFactory.getFile();
    StringBuffer buf = new StringBuffer();
    if (message == null || message.trim().length() == 0) {
        buf.append("EXAMPLE: log error / log 100");
    }else {
        String str[] = message.split(" ");
        if (! StringUtils.isInteger(str[0])){
            LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
        } else {
            int SHOW_LOG_LENGTH = Integer.parseInt(str[0]);
            
            if (file != null && file.exists()) {
                try{
                    FileInputStream fis = new FileInputStream(file);
                    FileChannel filechannel = fis.getChannel();
                    size = filechannel.size();
                    ByteBuffer bb;
                    if (size <= SHOW_LOG_LENGTH) {
                        bb = ByteBuffer.allocate((int) size);
                        filechannel.read(bb, 0);
                    } else {
                        int pos = (int) (size - SHOW_LOG_LENGTH);
                        bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
                        filechannel.read(bb, pos);
                    }
                    bb.flip();
                    String content = new String(bb.array()).replace("<", "&lt;")
                    .replace(">", "&gt;").replace("\n", "<br/><br/>");
                    buf.append("\r\ncontent:"+content);
                    
                    buf.append("\r\nmodified:"+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                    .format(new Date(file.lastModified()))));
                    buf.append("\r\nsize:"+size +"\r\n");
                }catch (Exception e) {
                    buf.append(e.getMessage());
                }
            }else {
                size = 0;
                buf.append("\r\nMESSAGE: log file not exists or log appender is console .");
            }
        }
    }
    buf.append("\r\nCURRENT LOG LEVEL:"+ LoggerFactory.getLevel())
    .append("\r\nCURRENT LOG APPENDER:"+ (file == null ? "console" : file.getAbsolutePath()));
    return buf.toString();
}
 
Example 11
Source File: LogTelnetHandler.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public String telnet(Channel channel, String message) {
    long size = 0 ;
    File file = LoggerFactory.getFile();
    StringBuffer buf = new StringBuffer();
    if (message == null || message.trim().length() == 0) {
        buf.append("EXAMPLE: log error / log 100");
    }else {
        String str[] = message.split(" ");
        if (! StringUtils.isInteger(str[0])){
            LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
        } else {
            int SHOW_LOG_LENGTH = Integer.parseInt(str[0]);
            
            if (file != null && file.exists()) {
                try{
                    FileInputStream fis = new FileInputStream(file);
                    try {
                     FileChannel filechannel = fis.getChannel();
                     try {
                      size = filechannel.size();
                      ByteBuffer bb;
                      if (size <= SHOW_LOG_LENGTH) {
                          bb = ByteBuffer.allocate((int) size);
                          filechannel.read(bb, 0);
                      } else {
                          int pos = (int) (size - SHOW_LOG_LENGTH);
                          bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
                          filechannel.read(bb, pos);
                      }
                      bb.flip();
                      String content = new String(bb.array()).replace("<", "&lt;")
                      .replace(">", "&gt;").replace("\n", "<br/><br/>");
                      buf.append("\r\ncontent:"+content);
                      
                      buf.append("\r\nmodified:"+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                      .format(new Date(file.lastModified()))));
                      buf.append("\r\nsize:"+size +"\r\n");
                     } finally {
                     	filechannel.close();
                     }
                    } finally {
                    	fis.close();
                    }
                }catch (Exception e) {
                    buf.append(e.getMessage());
                }
            }else {
                size = 0;
                buf.append("\r\nMESSAGE: log file not exists or log appender is console .");
            }
        }
    }
    buf.append("\r\nCURRENT LOG LEVEL:"+ LoggerFactory.getLevel())
    .append("\r\nCURRENT LOG APPENDER:"+ (file == null ? "console" : file.getAbsolutePath()));
    return buf.toString();
}
 
Example 12
Source File: LogTelnetHandler.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
public String telnet(Channel channel, String message) {
    long size;
    File file = LoggerFactory.getFile();
    StringBuilder buf = new StringBuilder();
    if (message == null || message.trim().length() == 0) {
        buf.append("EXAMPLE: log error / log 100");
    } else {
        String str[] = message.split(" ");
        if (!StringUtils.isInteger(str[0])) {
            LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
        } else {
            int SHOW_LOG_LENGTH = Integer.parseInt(str[0]);

            if (file != null && file.exists()) {
                try {
                    FileInputStream fis = new FileInputStream(file);
                    FileChannel filechannel = fis.getChannel();
                    size = filechannel.size();
                    ByteBuffer bb;
                    if (size <= SHOW_LOG_LENGTH) {
                        bb = ByteBuffer.allocate((int) size);
                        filechannel.read(bb, 0);
                    } else {
                        int pos = (int) (size - SHOW_LOG_LENGTH);
                        bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
                        filechannel.read(bb, pos);
                    }
                    bb.flip();
                    String content = new String(bb.array()).replace("<", "&lt;")
                            .replace(">", "&gt;").replace("\n", "<br/><br/>");
                    buf.append("\r\ncontent:" + content);

                    buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                            .format(new Date(file.lastModified()))));
                    buf.append("\r\nsize:" + size + "\r\n");
                } catch (Exception e) {
                    buf.append(e.getMessage());
                }
            } else {
                size = 0;
                buf.append("\r\nMESSAGE: log file not exists or log appender is console .");
            }
        }
    }
    buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel())
            .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath()));
    return buf.toString();
}
 
Example 13
Source File: LogTelnetHandler.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@Override
public String telnet(Channel channel, String message) {
    long size = 0;
    File file = LoggerFactory.getFile();
    StringBuffer buf = new StringBuffer();
    if (message == null || message.trim().length() == 0) {
        buf.append("EXAMPLE: log error / log 100");
    } else {
        String str[] = message.split(" ");
        if (!StringUtils.isInteger(str[0])) {
            LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
        } else {
            int SHOW_LOG_LENGTH = Integer.parseInt(str[0]);

            if (file != null && file.exists()) {
                try {
                    FileInputStream fis = new FileInputStream(file);
                    try {
                        FileChannel filechannel = fis.getChannel();
                        try {
                            size = filechannel.size();
                            ByteBuffer bb;
                            if (size <= SHOW_LOG_LENGTH) {
                                bb = ByteBuffer.allocate((int) size);
                                filechannel.read(bb, 0);
                            } else {
                                int pos = (int) (size - SHOW_LOG_LENGTH);
                                bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
                                filechannel.read(bb, pos);
                            }
                            bb.flip();
                            String content = new String(bb.array()).replace("<", "&lt;")
                                    .replace(">", "&gt;").replace("\n", "<br/><br/>");
                            buf.append("\r\ncontent:" + content);

                            buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                                    .format(new Date(file.lastModified()))));
                            buf.append("\r\nsize:" + size + "\r\n");
                        } finally {
                            filechannel.close();
                        }
                    } finally {
                        fis.close();
                    }
                } catch (Exception e) {
                    buf.append(e.getMessage());
                }
            } else {
                size = 0;
                buf.append("\r\nMESSAGE: log file not exists or log appender is console .");
            }
        }
    }
    buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel())
            .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath()));
    return buf.toString();
}
 
Example 14
Source File: LogTelnetHandler.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public String telnet(Channel channel, String message) {
    long size = 0 ;
    File file = LoggerFactory.getFile();
    StringBuffer buf = new StringBuffer();
    if (message == null || message.trim().length() == 0) {
        buf.append("EXAMPLE: log error / log 100");
    }else {
        String str[] = message.split(" ");
        if (! StringUtils.isInteger(str[0])){
            LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
        } else {
            int SHOW_LOG_LENGTH = Integer.parseInt(str[0]);
            
            if (file != null && file.exists()) {
                try{
                    FileInputStream fis = new FileInputStream(file);
                    FileChannel filechannel = fis.getChannel();
                    size = filechannel.size();
                    ByteBuffer bb;
                    if (size <= SHOW_LOG_LENGTH) {
                        bb = ByteBuffer.allocate((int) size);
                        filechannel.read(bb, 0);
                    } else {
                        int pos = (int) (size - SHOW_LOG_LENGTH);
                        bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
                        filechannel.read(bb, pos);
                    }
                    bb.flip();
                    String content = new String(bb.array()).replace("<", "&lt;")
                    .replace(">", "&gt;").replace("\n", "<br/><br/>");
                    buf.append("\r\ncontent:"+content);
                    
                    buf.append("\r\nmodified:"+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                    .format(new Date(file.lastModified()))));
                    buf.append("\r\nsize:"+size +"\r\n");
                }catch (Exception e) {
                    buf.append(e.getMessage());
                }
            }else {
                size = 0;
                buf.append("\r\nMESSAGE: log file not exists or log appender is console .");
            }
        }
    }
    buf.append("\r\nCURRENT LOG LEVEL:"+ LoggerFactory.getLevel())
    .append("\r\nCURRENT LOG APPENDER:"+ (file == null ? "console" : file.getAbsolutePath()));
    return buf.toString();
}
 
Example 15
Source File: LogTelnetHandler.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public String telnet(Channel channel, String message) {
    long size = 0 ;
    File file = LoggerFactory.getFile();
    StringBuffer buf = new StringBuffer();
    if (message == null || message.trim().length() == 0) {
        buf.append("EXAMPLE: log error / log 100");
    }else {
        String str[] = message.split(" ");
        if (! StringUtils.isInteger(str[0])){
            LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
        } else {
            int SHOW_LOG_LENGTH = Integer.parseInt(str[0]);
            
            if (file != null && file.exists()) {
                try{
                    FileInputStream fis = new FileInputStream(file);
                    try {
                     FileChannel filechannel = fis.getChannel();
                     try {
                      size = filechannel.size();
                      ByteBuffer bb;
                      if (size <= SHOW_LOG_LENGTH) {
                          bb = ByteBuffer.allocate((int) size);
                          filechannel.read(bb, 0);
                      } else {
                          int pos = (int) (size - SHOW_LOG_LENGTH);
                          bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
                          filechannel.read(bb, pos);
                      }
                      bb.flip();
                      String content = new String(bb.array()).replace("<", "&lt;")
                      .replace(">", "&gt;").replace("\n", "<br/><br/>");
                      buf.append("\r\ncontent:"+content);
                      
                      buf.append("\r\nmodified:"+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                      .format(new Date(file.lastModified()))));
                      buf.append("\r\nsize:"+size +"\r\n");
                     } finally {
                     	filechannel.close();
                     }
                    } finally {
                    	fis.close();
                    }
                }catch (Exception e) {
                    buf.append(e.getMessage());
                }
            }else {
                size = 0;
                buf.append("\r\nMESSAGE: log file not exists or log appender is console .");
            }
        }
    }
    buf.append("\r\nCURRENT LOG LEVEL:"+ LoggerFactory.getLevel())
    .append("\r\nCURRENT LOG APPENDER:"+ (file == null ? "console" : file.getAbsolutePath()));
    return buf.toString();
}
 
Example 16
Source File: LogTelnetHandler.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public String telnet(Channel channel, String message) {
    long size = 0 ;
    File file = LoggerFactory.getFile();
    StringBuffer buf = new StringBuffer();
    if (message == null || message.trim().length() == 0) {
        buf.append("EXAMPLE: log error / log 100");
    }else {
        String str[] = message.split(" ");
        if (! StringUtils.isInteger(str[0])){
            LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
        } else {
            int SHOW_LOG_LENGTH = Integer.parseInt(str[0]);
            
            if (file != null && file.exists()) {
                try{
                    FileInputStream fis = new FileInputStream(file);
                    FileChannel filechannel = fis.getChannel();
                    size = filechannel.size();
                    ByteBuffer bb;
                    if (size <= SHOW_LOG_LENGTH) {
                        bb = ByteBuffer.allocate((int) size);
                        filechannel.read(bb, 0);
                    } else {
                        int pos = (int) (size - SHOW_LOG_LENGTH);
                        bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
                        filechannel.read(bb, pos);
                    }
                    bb.flip();
                    String content = new String(bb.array()).replace("<", "&lt;")
                    .replace(">", "&gt;").replace("\n", "<br/><br/>");
                    buf.append("\r\ncontent:"+content);
                    
                    buf.append("\r\nmodified:"+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                    .format(new Date(file.lastModified()))));
                    buf.append("\r\nsize:"+size +"\r\n");
                }catch (Exception e) {
                    buf.append(e.getMessage());
                }
            }else {
                size = 0;
                buf.append("\r\nMESSAGE: log file not exists or log appender is console .");
            }
        }
    }
    buf.append("\r\nCURRENT LOG LEVEL:"+ LoggerFactory.getLevel())
    .append("\r\nCURRENT LOG APPENDER:"+ (file == null ? "console" : file.getAbsolutePath()));
    return buf.toString();
}
 
Example 17
Source File: LogTelnetHandler.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public String telnet(Channel channel, String message) {
    long size = 0 ;
    File file = LoggerFactory.getFile();
    StringBuffer buf = new StringBuffer();
    if (message == null || message.trim().length() == 0) {
        buf.append("EXAMPLE: log error / log 100");
    }else {
        String str[] = message.split(" ");
        if (! StringUtils.isInteger(str[0])){
            LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
        } else {
            int SHOW_LOG_LENGTH = Integer.parseInt(str[0]);
            
            if (file != null && file.exists()) {
                try{
                    FileInputStream fis = new FileInputStream(file);
                    try {
                     FileChannel filechannel = fis.getChannel();
                     try {
                      size = filechannel.size();
                      ByteBuffer bb;
                      if (size <= SHOW_LOG_LENGTH) {
                          bb = ByteBuffer.allocate((int) size);
                          filechannel.read(bb, 0);
                      } else {
                          int pos = (int) (size - SHOW_LOG_LENGTH);
                          bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
                          filechannel.read(bb, pos);
                      }
                      bb.flip();
                      String content = new String(bb.array()).replace("<", "&lt;")
                      .replace(">", "&gt;").replace("\n", "<br/><br/>");
                      buf.append("\r\ncontent:"+content);
                      
                      buf.append("\r\nmodified:"+(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                      .format(new Date(file.lastModified()))));
                      buf.append("\r\nsize:"+size +"\r\n");
                     } finally {
                     	filechannel.close();
                     }
                    } finally {
                    	fis.close();
                    }
                }catch (Exception e) {
                    buf.append(e.getMessage());
                }
            }else {
                size = 0;
                buf.append("\r\nMESSAGE: log file not exists or log appender is console .");
            }
        }
    }
    buf.append("\r\nCURRENT LOG LEVEL:"+ LoggerFactory.getLevel())
    .append("\r\nCURRENT LOG APPENDER:"+ (file == null ? "console" : file.getAbsolutePath()));
    return buf.toString();
}
 
Example 18
Source File: LogTelnetHandler.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@Override
public String telnet(Channel channel, String message) {
    long size = 0;
    File file = LoggerFactory.getFile();
    StringBuffer buf = new StringBuffer();
    if (message == null || message.trim().length() == 0) {
        buf.append("EXAMPLE: log error / log 100");
    } else {
        String str[] = message.split(" ");
        if (!StringUtils.isInteger(str[0])) {
            LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
        } else {
            int SHOW_LOG_LENGTH = Integer.parseInt(str[0]);

            if (file != null && file.exists()) {
                try {
                    FileInputStream fis = new FileInputStream(file);
                    FileChannel filechannel = fis.getChannel();
                    size = filechannel.size();
                    ByteBuffer bb;
                    if (size <= SHOW_LOG_LENGTH) {
                        bb = ByteBuffer.allocate((int) size);
                        filechannel.read(bb, 0);
                    } else {
                        int pos = (int) (size - SHOW_LOG_LENGTH);
                        bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
                        filechannel.read(bb, pos);
                    }
                    bb.flip();
                    String content = new String(bb.array()).replace("<", "&lt;")
                            .replace(">", "&gt;").replace("\n", "<br/><br/>");
                    buf.append("\r\ncontent:" + content);

                    buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                            .format(new Date(file.lastModified()))));
                    buf.append("\r\nsize:" + size + "\r\n");
                } catch (Exception e) {
                    buf.append(e.getMessage());
                }
            } else {
                size = 0;
                buf.append("\r\nMESSAGE: log file not exists or log appender is console .");
            }
        }
    }
    buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel())
            .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath()));
    return buf.toString();
}