Ejemplo n.º 1
0
  /** This method is synchronized in order to avoid messy of logs' order. */
  private synchronized void log(int logType, String msg, Object... args) {
    if (settings.getLogLevel() == LogLevel.NONE) {
      return;
    }
    String tag = getTag();
    String message = createMessage(msg, args);
    int methodCount = getMethodCount();

    logTopBorder(logType, tag);
    logHeaderContent(logType, tag, methodCount);

    // get bytes of message with system's default charset (which is UTF-8 for Android)
    byte[] bytes = message.getBytes();
    int length = bytes.length;
    if (length <= CHUNK_SIZE) {
      if (methodCount > 0) {
        logDivider(logType, tag);
      }
      logContent(logType, tag, message);
      logBottomBorder(logType, tag);
      return;
    }
    if (methodCount > 0) {
      logDivider(logType, tag);
    }
    for (int i = 0; i < length; i += CHUNK_SIZE) {
      int count = Math.min(length - i, CHUNK_SIZE);
      // create a new String with system's default charset (which is UTF-8 for Android)
      logContent(logType, tag, new String(bytes, i, count));
    }
    logBottomBorder(logType, tag);
  }
Ejemplo n.º 2
0
 /** This method is synchronized in order to avoid messy of logs' order. */
 private synchronized void log(int priority, Throwable throwable, String msg, Object... args) {
   if (settings.getLogLevel() == LogLevel.NONE) {
     return;
   }
   String tag = getTag();
   String message = createMessage(msg, args);
   log(priority, tag, message, throwable);
 }
Ejemplo n.º 3
0
  @Override
  public synchronized void log(int priority, String tag, String message, Throwable throwable) {
    if (settings.getLogLevel() == LogLevel.NONE) {
      return;
    }
    if (throwable != null && message != null) {
      message += " : " + Helper.getStackTraceString(throwable);
    }
    if (throwable != null && message == null) {
      message = Helper.getStackTraceString(throwable);
    }
    if (message == null) {
      message = "No message/exception is set";
    }
    int methodCount = getMethodCount();
    if (Helper.isEmpty(message)) {
      message = "Empty/NULL log message";
    }

    logTopBorder(priority, tag);
    logHeaderContent(priority, tag, methodCount);

    // get bytes of message with system's default charset (which is UTF-8 for Android)
    byte[] bytes = message.getBytes();
    int length = bytes.length;
    if (length <= CHUNK_SIZE) {
      if (methodCount > 0) {
        logDivider(priority, tag);
      }
      logContent(priority, tag, message);
      logBottomBorder(priority, tag);
      return;
    }
    if (methodCount > 0) {
      logDivider(priority, tag);
    }
    for (int i = 0; i < length; i += CHUNK_SIZE) {
      int count = Math.min(length - i, CHUNK_SIZE);
      // create a new String with system's default charset (which is UTF-8 for Android)
      logContent(priority, tag, new String(bytes, i, count));
    }
    logBottomBorder(priority, tag);
  }
Ejemplo n.º 4
0
  public static Logger initLogger() {
    Logger initlogger = Logger.getLogger(settings.getMainClass());
    initlogger.setLevel(settings.getLogLevel());
    boolean addconsole = false;
    if (settings.getLogToFile()) {
      try {
        Handler handler = new FileHandler(settings.getLogFile(), true);
        handler.setFormatter(new SimpleFormatter());
        initlogger.addHandler(handler);
      } catch (Exception e) {
        Logger().warning("Could not set logfile " + settings.getLogFile() + ": " + e.getMessage());
        addconsole = true;
      }
    }
    addconsole = settings.getLogToConsole() || addconsole;
    if (addconsole) {
      initlogger.addHandler(new ConsoleHandler());
    }
    // restore original log state
    logger.setLevel(templevel);
    templevel = null;

    return initlogger;
  }