Java Code Examples for org.osgi.service.log.LogService#LOG_WARNING

The following examples show how to use org.osgi.service.log.LogService#LOG_WARNING . 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: LoggerDelegate.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void log(Object context, int level, String message, Throwable exception) {
  // Oddly LogService#LOG_xxx are deprecated in favour of LogLevel enum, but
  // the LogLevel enum does not provide integer mappings.
  switch (level) {
    case LogService.LOG_ERROR:
      logger.error(message, exception);
      break;
    case LogService.LOG_WARNING:
      logger.warn(message, exception);
      break;
    case LogService.LOG_INFO:
      logger.info(message, exception);
      break;
    case LogService.LOG_DEBUG:
      logger.debug(message, exception);
      break;
    default:
      logger.debug(message, exception);
      break;
  }
}
 
Example 2
Source File: LoggerDelegate.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public boolean isLoggable(int level) {
  // Oddly LogService#LOG_xxx are deprecated in favour of LogLevel enum, but
  // the LogLevel enum does not provide integer mappings.
  switch (level) {
    case LogService.LOG_ERROR:
      return isErrorEnabled();
    case LogService.LOG_WARNING:
      return isWarnEnabled();
    case LogService.LOG_INFO:
      return isInfoEnabled();
    case LogService.LOG_DEBUG:
      return isDebugEnabled();
    default:
      return false;
  }
}
 
Example 3
Source File: OsgiLogHandler.java    From vespa with Apache License 2.0 6 votes vote down vote up
public static int toServiceLevel(Level level) {
    int val = level.intValue();
    if (val >= Level.SEVERE.intValue()) {
        return LogService.LOG_ERROR;
    }
    if (val >= Level.WARNING.intValue()) {
        return LogService.LOG_WARNING;
    }
    if (val >= Level.INFO.intValue()) {
        return LogService.LOG_INFO;
    }
    // Level.CONFIG
    // Level.FINE
    // Level.FINER
    // Level.FINEST
    return LogService.LOG_DEBUG;
}
 
Example 4
Source File: ConsoleLogFormatter.java    From vespa with Apache License 2.0 6 votes vote down vote up
private StringBuilder formatLevel(LogEntry entry, StringBuilder out) {
    switch (entry.getLevel()) {
    case LogService.LOG_ERROR:
        out.append("error");
        break;
    case LogService.LOG_WARNING:
        out.append("warning");
        break;
    case LogService.LOG_INFO:
        out.append("info");
        break;
    case LogService.LOG_DEBUG:
        out.append("debug");
        break;
    default:
        out.append("unknown");
        break;
    }
    return out;
}
 
Example 5
Source File: OsgiLogHandlerTestCase.java    From vespa with Apache License 2.0 6 votes vote down vote up
@Test
public void requireThatCustomLogLevelsAreConverted() {
    for (int i = Level.ALL.intValue() - 69; i < Level.OFF.intValue() + 69; ++i) {
        int expectedLevel;
        if (i >= Level.SEVERE.intValue()) {
            expectedLevel = LogService.LOG_ERROR;
        } else if (i >= Level.WARNING.intValue()) {
            expectedLevel = LogService.LOG_WARNING;
        } else if (i >= Level.INFO.intValue()) {
            expectedLevel = LogService.LOG_INFO;
        } else {
            expectedLevel = LogService.LOG_DEBUG;
        }
        assertLogLevel(expectedLevel, new MyLogLevel(i));
    }
}
 
Example 6
Source File: LogUtil.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Converts a string representing a log severity level to an int.
 *
 * @param level
 *            The string to convert.
 * @param def
 *            Default value to use if the string is not recognized
 *            as a log level.
 * @return the log level, or the default value if the string can not
 *         be recognized.
 */
static public int toLevel(String level, int def) {
  if (level==null) {
    return def;
  }

  level = level.trim();
  if (level.equalsIgnoreCase("INFO")) {
    return LogService.LOG_INFO;
  } else if (level.equalsIgnoreCase("DEBUG")) {
    return LogService.LOG_DEBUG;
  } else if (level.equalsIgnoreCase("WARNING")) {
    return LogService.LOG_WARNING;
  } else if (level.equalsIgnoreCase("ERROR")) {
    return LogService.LOG_ERROR;
  } else if (level.equalsIgnoreCase("DEFAULT")) {
    return 0;
  }
  return def;
}
 
Example 7
Source File: OsgiSl4fjLoggingAdapter.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void logged(LogEntry entry){
	
	Bundle bundle = entry.getBundle();
	String message =
		(bundle != null) ? "[" + bundle.getSymbolicName() + "] " + entry.getMessage()
				: entry.getMessage();
	Throwable exception = entry.getException();
	
	switch (entry.getLevel()) {
	case LogService.LOG_ERROR:
		logger.error(message, exception);
		break;
	case LogService.LOG_WARNING:
		logger.warn(message, exception);
		break;
	case LogService.LOG_INFO:
		logger.info(message, exception);
		break;
	default:
		logger.debug(message, exception);
		break;
	}
	
}
 
Example 8
Source File: LogUtil.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Converts from a numeric log severity level to a left justified
 * string of at least the given length.
 *
 * @param level
 *            is the log severity level.
 * @param length
 *            the minimum length of the resulting string.
 * @return left justified string representation of a numeric log level.
 */
static public String fromLevel(int level, int length) {
  final StringBuffer sb = new StringBuffer(length > 7 ? length : 7);
  switch (level) {
  case LogService.LOG_INFO:
    sb.append("info");
    break;
  case LogService.LOG_DEBUG:
    sb.append("debug");
    break;
  case LogService.LOG_WARNING:
    sb.append("Warning");
    break;
  case LogService.LOG_ERROR:
    sb.append("ERROR");
    break;
  case 0:
    sb.append("DEFAULT");
    break;
  default:
    sb.append("[");
    sb.append(level);
    sb.append("]");
  }
  for (int i = sb.length(); i < length; i++) {
    sb.append(" ");
  }
  return sb.toString();
}
 
Example 9
Source File: LogFrameworkListener.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * The framework event callback method inserts all framework events into
 * the log. Events of type <code>error</code> are logged at the error
 * level other event types are logged on the info level.
 * <p/>
 * FrameworkListener callback.
 * 
 * @param fe
 *            the framework event that has occurred.
 */
public void frameworkEvent(FrameworkEvent fe) {
    int level = LogService.LOG_INFO;
    String msg = null;
    // We always include the Exception even though
    // the specification says differently
    Throwable thr = fe.getThrowable();
    switch (fe.getType()) {
    case FrameworkEvent.ERROR:
        msg = "FrameworkEvent ERROR";
        level = LogService.LOG_ERROR;
        break;
    case FrameworkEvent.STARTED:
        msg = "FrameworkEvent STARTED";
        level = LogService.LOG_INFO;
        break;
    case FrameworkEvent.STARTLEVEL_CHANGED:
        msg = "FrameworkEvent STARTLEVEL_CHANGED";
        level = LogService.LOG_INFO;
        break;
    case FrameworkEvent.PACKAGES_REFRESHED:
        msg = "FrameworkEvent PACKAGES_REFRESHED";
        level = LogService.LOG_INFO;
        break;
    case FrameworkEvent.WARNING:
        msg   = "FrameworkEvent WARNING";
        level = LogService.LOG_INFO; // sic! According to spec.
        break;
    case FrameworkEvent.INFO:
        msg   = "FrameworkEvent INFO";
        level = LogService.LOG_INFO;
        break;
    default:
        msg = "FrameworkEvent <" + fe.getType() + ">";
        level = LogService.LOG_WARNING;
        break;     
    }
    lrsf.log(new LogEntryImpl(fe.getBundle(), level, msg, thr));
}
 
Example 10
Source File: LogTracker.java    From osgi.iot.contest.sdk with Apache License 2.0 5 votes vote down vote up
private Level getLevel(int level) {
	switch (level) {
	case LogService.LOG_ERROR:
		return Level.error;
	case LogService.LOG_WARNING:
		return Level.warning;
	case LogService.LOG_INFO:
		return Level.info;
	default:
		return Level.debug;
	}
}