Java Code Examples for ch.qos.logback.classic.Level#toLevel()

The following examples show how to use ch.qos.logback.classic.Level#toLevel() . 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: ContainerRuntimeInfo.java    From dapeng-soa with Apache License 2.0 6 votes vote down vote up
@Override
public void setLoggerLevel(String loggerName, String levelStr) {
    if (loggerName == null) {
        return;
    }
    if (levelStr == null) {
        return;
    }
    loggerName = loggerName.trim();
    levelStr = levelStr.trim();

    LOGGER.info("Jmx Trying to set logger level [" + levelStr + "] to logger [" + loggerName +"]");

    ch.qos.logback.classic.Logger logger = loggerContext.getLogger(loggerName);
    if ("null".equalsIgnoreCase(levelStr)) {
        logger.setLevel(null);
    } else {
        Level level = Level.toLevel(levelStr, null);
        if (level != null) {
            logger.setLevel(level);
        }
    }
}
 
Example 2
Source File: LogConfig.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
@POST
@Produces(MediaType.TEXT_HTML)
public String post(
    @FormParam("logger") String loggerName,
    @FormParam("level") String loggerLevel) throws TemplateException {

  Optional<String> configChange = Optional.empty();
  if (loggerName != null && loggerLevel != null) {
    Logger logger = (Logger) LoggerFactory.getLogger(loggerName);
    Level newLevel = Level.toLevel(loggerLevel, null);
    logger.setLevel(newLevel);

    configChange = Optional.of(String.format("%s level changed to %s", loggerName, loggerLevel));
  }

  return displayPage(configChange);
}
 
Example 3
Source File: LogbackHelper.java    From arthas with Apache License 2.0 6 votes vote down vote up
public static Boolean updateLevel(String name, String level) {
    if (Logback) {
        try {
            Level l = Level.toLevel(level, Level.ERROR);
            LoggerContext loggerContext = (LoggerContext) loggerFactoryInstance;

            Logger logger = loggerContext.exists(name);
            if (logger != null) {
                logger.setLevel(l);
                return true;
            }
        } catch (Throwable t) {
            // ignore
        }
        return false;
    }
    return null;
}
 
Example 4
Source File: LoggingApis.java    From soabase with Apache License 2.0 6 votes vote down vote up
@PUT
@Path("levels")
@Consumes(MediaType.APPLICATION_JSON)
public Response setLogLevels(List<LogLevel> levels) throws JsonProcessingException
{
    LoggerContext loggerContext = getLoggerContext();
    for ( LogLevel logLevel : levels )
    {
        ch.qos.logback.classic.Logger logger = loggerContext.getLogger(logLevel.getName());
        if ( logger != null )
        {
            Level newLevel = Level.toLevel(logLevel.getLevel(), null);
            logger.setLevel(newLevel);
            log.info(String.format("Setting log level. Name (%s) - Level (%s)", logLevel.getName(), logLevel.getLevel()));
        }
        else
        {
            log.warn("Logger not found for: " + logLevel.getName());
        }
    }
    return Response.ok().build();
}
 
Example 5
Source File: AionLoggerFactory.java    From aion with MIT License 5 votes vote down vote up
private static Map<LogEnum, Level> constructModuleLoglevelMap(Map<LogEnum, LogLevel> _moduleToLevelMap) {
    Map<LogEnum, Level> modules = new HashMap<>();
    for (LogEnum mod : LogEnum.values()) {
        LogLevel modLevel = _moduleToLevelMap.get(mod);
        if (modLevel != null) {
            // if we can't translate log-level for some reason, default to WARN
            Level level = Level.toLevel(modLevel.name(), Level.WARN);
            modules.put(mod, level);
        } else {
            modules.put(mod, Level.WARN);
        }
    }

    return modules;
}
 
Example 6
Source File: Main.java    From digdag with Apache License 2.0 5 votes vote down vote up
private static void configureLogging(String level, String logPath)
{
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(context);
    context.reset();

    // logback uses system property to embed variables in XML file
    Level lv = Level.toLevel(level.toUpperCase(), Level.DEBUG);
    System.setProperty("digdag.log.level", lv.toString());

    String name;
    if (logPath.equals("-")) {
        if (System.console() != null) {
            name = "/digdag/cli/logback-color.xml";
        } else {
            name = "/digdag/cli/logback-console.xml";
        }
    } else {
        System.setProperty("digdag.log.path", logPath);
        name = "/digdag/cli/logback-file.xml";
    }
    try {
        configurator.doConfigure(Main.class.getResource(name));
    } catch (JoranException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 7
Source File: EnvironmentVariablesLogLevelPropagator.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void setLoggerLevel(String loggerConfig) {
  String[] parts = loggerConfig.split("=", 2);

  if (parts.length < 2) {
    return;
  }
  String loggerName = parts[0];
  String levelStr = parts[1];

  if (levelStr.isEmpty() || loggerName.isEmpty()) {
    return;
  }

  loggerName = loggerName.trim();
  levelStr = levelStr.trim();

  LoggerContext lc = (LoggerContext) context;

  Logger logger = lc.getLogger(loggerName);
  if ("null".equalsIgnoreCase(levelStr)) {
    logger.setLevel(null);
  } else {
    Level level = Level.toLevel(levelStr, null);
    if (level != null) {
      logger.setLevel(level);
    }
  }
}
 
Example 8
Source File: SimpleLoggerManager.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public void changeLevel(String level, String loggerName){
		LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
		Logger targetLogger = loggerContext.getLogger(loggerName);
		if(targetLogger==null || StringUtils.isBlank(level)){
			throw new ServiceException("logger not found or error level! logger: " + loggerName + ", level: " + level);
		}
		Level targetLevel = Level.toLevel(level);
		if(targetLevel.equals(targetLogger.getLevel())){
//			throw new ServiceException("logger's level is equals target level");
			return ;
		}
		loggerOriginLevelHoders.putIfAbsent(targetLogger, Optional.ofNullable(targetLogger.getLevel()));
		targetLogger.setLevel(targetLevel);
		logger.info("logger[{}] change level to {}", loggerName, level);
	}
 
Example 9
Source File: LogLevelConverter.java    From halyard with Apache License 2.0 5 votes vote down vote up
@Override
public Level convert(String value) {
  Level res = Level.toLevel(value, Level.OFF);

  if (!res.levelStr.equalsIgnoreCase(value)) {
    throw new IllegalArgumentException(
        "Log level "
            + value
            + " is not valid. The options are: OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.");
  }

  return res;
}
 
Example 10
Source File: BaleenLogging.java    From baleen with Apache License 2.0 5 votes vote down vote up
private Level convertToLevel(String s) {
  if (Strings.isNullOrEmpty(s)) {
    return null;
  } else {
    return Level.toLevel(s);
  }
}
 
Example 11
Source File: LogbackConfiguration.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("java:S4792") // Logger configuration is ok
public void setLogLevel(final String logLevel) {
    final Level level = Level.toLevel(logLevel);
    getLogger().setLevel(level);
}
 
Example 12
Source File: Authorizer.java    From gcp-token-broker with Apache License 2.0 4 votes vote down vote up
private static void setLoggingLevel() {
    Level level = Level.toLevel(AppSettings.getInstance().getString(AppSettings.LOGGING_LEVEL));
    final Logger logger = org.slf4j.LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) logger;
    logbackLogger.setLevel(level);
}
 
Example 13
Source File: SystemEnvironment.java    From gocd with Apache License 2.0 4 votes vote down vote up
public Level pluginLoggingLevel(String pluginId) {
    return Level.toLevel(getPropertyImpl("plugin." + pluginId + ".log.level", "INFO"), Level.INFO);
}
 
Example 14
Source File: KonkerLogger.java    From konker-platform with Apache License 2.0 4 votes vote down vote up
public Level getEffectiveLevel() {
    return Level.toLevel(this.effectiveLevelInt);
}
 
Example 15
Source File: AbstractNameAndLevelLogInclusionRule.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
@Override
protected void postResolve()
{
    super.postResolve();
    _filter = new LoggerNameAndLevelFilter(getLoggerName(), Level.toLevel(getLevel().name()));
}
 
Example 16
Source File: AbstractPredicateLogInclusionRule.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
@Override
protected void postResolve()
{
    super.postResolve();
    _filter = new PredicateAndLoggerNameAndLevelFilter(getLoggerName(), Level.toLevel(getLevel().name()), getPredicate());
}
 
Example 17
Source File: LoggerHandler.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected boolean handlePut(HttpServletRequest request,
		HttpServletResponse response, ILogService logService, IPath path)
		throws ServletException {

	URI baseLocation = getURI(request);

	try {
		String loggerName = path.segment(0);
		JSONObject toPut = OrionServlet.readJSONRequest(request);

		Logger logger = logService.getLogger(loggerName);
		if (logger == null) {
			final String msg = NLS
					.bind("Logger not found: {0}", loggerName);
			final ServerStatus error = new ServerStatus(IStatus.ERROR,
					HttpServletResponse.SC_NOT_FOUND, msg, null);
			return statusHandler.handleRequest(request, response, error);
		}

		String putlevel = toPut.getString(LogConstants.KEY_LOGGER_LEVEL);
		Level level = Level.toLevel(putlevel, logger.getLevel());
		logger.setLevel(level);

		LoggerResource loggerResource = new LoggerResource();
		loggerResource.setBaseLocation(baseLocation);
		loggerResource.setName(logger.getName());
		loggerResource.setLevel(logger.getLevel());
		loggerResource.setEffectiveLevel(logger.getEffectiveLevel());

		JSONObject result = loggerResource.toJSON();
		OrionServlet.writeJSONResponse(request, response, result);
		response.setHeader(ProtocolConstants.HEADER_LOCATION,
				result.getString(ProtocolConstants.KEY_LOCATION));
		return true;

	} catch (Exception e) {
		return statusHandler.handleRequest(request, response,
				new ServerStatus(IStatus.ERROR,
						HttpServletResponse.SC_BAD_REQUEST, e.getMessage(),
						e));
	}
}
 
Example 18
Source File: LoggerBuilder.java    From nuls-v2 with MIT License 4 votes vote down vote up
public static NulsLogger getLogger(String fileName,int chainId) {
    Level level = StringUtils.isNotBlank(System.getProperty("log.level")) ? Level.toLevel(System.getProperty("log.level")) : DEFAULT_LEVEL;
    return getLogger("chain_"+chainId+ "_" +fileName, level, level);
}
 
Example 19
Source File: LoggerBuilder.java    From nuls-v2 with MIT License 4 votes vote down vote up
public static NulsLogger getLogger(String fileName) {
    Level level = StringUtils.isNotBlank(System.getProperty("log.level")) ? Level.toLevel(System.getProperty("log.level")) : DEFAULT_LEVEL;
    return getLogger(fileName, level, level);
}
 
Example 20
Source File: LogLevelConverter.java    From jd-cmd with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Level convert(String value) {
    return Level.toLevel(value, Level.INFO);
}