solr日志级别修改源代码摘取

核心代码:

public void setLogLevel(String category, String level) {

org.apache.log4j.Logger log;

if(LoggerInfo.ROOT_NAME.equals(category)) {

log = org.apache.log4j.LogManager.getRootLogger();

} else {

log = org.apache.log4j.Logger.getLogger(category);

}

if(level==null||"unset".equals(level)||"null".equals(level)) {

log.setLevel(null);

}

else {

log.setLevel(org.apache.log4j.Level.toLevel(level));

}

}

public List<String> getAllLevels() {

return Arrays.asList(

org.apache.log4j.Level.ALL.toString(),

org.apache.log4j.Level.TRACE.toString(),

org.apache.log4j.Level.DEBUG.toString(),

org.apache.log4j.Level.INFO.toString(),

org.apache.log4j.Level.WARN.toString(),

org.apache.log4j.Level.ERROR.toString(),

org.apache.log4j.Level.FATAL.toString(),

org.apache.log4j.Level.OFF.toString());

}

public Collection<LoggerInfo> getAllLoggers() {

org.apache.log4j.Logger root = org.apache.log4j.LogManager.getRootLogger();

Map<String,LoggerInfo> map = new HashMap<String,LoggerInfo>();

Enumeration<?> loggers = org.apache.log4j.LogManager.getCurrentLoggers();

while (loggers.hasMoreElements()) {

org.apache.log4j.Logger logger = (org.apache.log4j.Logger)loggers.nextElement();

String name = logger.getName();

if( logger == root) {

continue;

}

map.put(name, new Log4jInfo(name, logger));

while (true) {

int dot = name.lastIndexOf(".");

if (dot < 0)

break;

name = name.substring(0, dot);

if(!map.containsKey(name)) {

map.put(name, new Log4jInfo(name, null));

}

}

}

map.put(LoggerInfo.ROOT_NAME, new Log4jInfo(LoggerInfo.ROOT_NAME, root));

return map.values();

}

依赖类LoggerInfo 

/*

* Licensed to the Apache Software Foundation (ASF) under one or more

* contributor license agreements.  See the NOTICE file distributed with

* this work for additional information regarding copyright ownership.

* The ASF licenses this file to You under the Apache License, Version 2.0

* (the "License"); you may not use this file except in compliance with

* the License.  You may obtain a copy of the License at

*

*     http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

/**

* Wrapper class for Logger implementaions

*/

public abstract class LoggerInfo implements Comparable<LoggerInfo> {

public static final String ROOT_NAME = "root";

protected final String name;

protected String level;

public LoggerInfo(String name) {

this.name = name;

}

public String getLevel() {

return level;

}

public String getName() {

return name;

}

public abstract boolean isSet();

//  public Map getInfo() {

//    Map info = new HashMap();

//    info.put("name", getName());

//    info.put("level", getLevel());

//    info.put("set", isSet());

//    return info;

//  }

@Override

public int compareTo(LoggerInfo other) {

if (this.equals(other))

return 0;

String tN = this.getName();

String oN = other.getName();

if(ROOT_NAME.equals(tN))

return -1;

if(ROOT_NAME.equals(oN))

return 1;

return tN.compareTo(oN);

}

}

依赖类Log4jInfo 

/**

* Licensed to the Apache Software Foundation (ASF) under one or more

* contributor license agreements.  See the NOTICE file distributed with

* this work for additional information regarding copyright ownership.

* The ASF licenses this file to You under the Apache License, Version 2.0

* (the "License"); you may not use this file except in compliance with

* the License.  You may obtain a copy of the License at

*

*     http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

public class Log4jInfo extends LoggerInfo {

final org.apache.log4j.Logger logger;

public Log4jInfo(String name, org.apache.log4j.Logger logger) {

super(name);

this.logger = logger;

}

@Override

public String getLevel() {

if(logger==null) {

return null;

}

Object level = logger.getLevel();

if(level==null) {

return null;

}

return level.toString();

}

@Override

public String getName() {

return name;

}

@Override

public boolean isSet() {

return (logger!=null && logger.getLevel()!=null);

}

}

用easyui做了一个简单的界面和修改

时间: 2024-08-28 04:17:48

solr日志级别修改源代码摘取的相关文章

Spark日志级别修改

摘要 在学习使用Spark的过程中,总是想对内部运行过程作深入的了解,其中DEBUG和TRACE级别的日志可以为我们提供详细和有用的信息,那么如何进行合理设置呢,不复杂但也绝不是将一个INFO换为TRACE那么简单. 主要问题 调整Spark日志级别的配置文件是$SPARK_HOME/conf/log4j.properties,默认级别是INFO,如果曾经将其改为DEBUG的朋友可能会有这样的经历,有用的信息还没看完,就被大量的心跳检测日志给淹没了. 解决办法 只将需要的日志级别调整为_TRAC

DEBUG技巧-设定合适的日志级别

有些技能只有踩过坑的人才能够掌握,能用来避免后来的坑,很多时候是用凌晨的时间换来的,我们通常把他叫做经验. 故事 这个一个关于springmvc的坑的故事. 某天晚上本打算一个小功能分分钟搞定上线,但页面总是报404错误,肉眼实在找不到原因. 各种手段折腾,断点,重启,重新打包,拍脑袋觉得代码没写错,url路径也ok,真心没问题,无数次f5就是不出来. 很多时候遇到一个bug越着急越搞不定,我就是这种情况,花了一两个小时时间,眼看都过0点了,此时我正用最后的手段,引入spring源码直接一步步d

修改Oracle的Job Scheduler 日志级别及删除运行日志

Job 运行久了会产生大量运行日志,这些信息可通过下面的方式清除: 1.创建job: Create job links to previous job class.   DBMS_SCHEDULER.create_job (     job_name        => 'test_log_job',     job_type        => 'PLSQL_BLOCK',     job_action      => 'BEGIN NULL; END;',     job_class

SpringBoot系列十一:SpringBoot整合Restful架构(使用 RestTemplate 模版实现 Rest 服务调用、Swagger 集成、动态修改日志级别)

1.概念:SpringBoot整合Restful架构 2.背景 Spring 与 Restful 整合才是微架构的核心,虽然在整个 SpringBoot(SpringCloud)之中提供有大量的服务方便整合,但是这些 整合都不如 Rest 重要,因为 Rest 是整个在微架构之中进行通讯的基础模式.那么对于 Rest 首先必须对其有一个最为核心的解释: 利用 JSON 实现数据的交互处理.而且 Spring 里面提供有一个非常强大的 RestTemplate 操作模版,利用此模版可以非常轻松的实

springboot动态修改日志级别+权限认证

1. springboot动态修改日志级别+权限认证 1.1. 需求 网上找到的动态修改日志级别的方式,基本都是没有权限验证的,或者特地关闭权限验证,但也没给出加上验证的解决方式 修改日志等级也是一个敏感操作,最好不能暴露地址直接修改,所以我研究了下,把权限验证加上了 1.2. 解决 1.2.1. pom 首先加上pom <dependency> <groupId>org.springframework.boot</groupId> <artifactId>

log4j2和logback动态修改日志级别工具类

工作中,有些场景需要动态修改线上日志记录器的打印日志级别, 本文的两个工具类使用的版本如下: ----------------logback--------------------- <dependency>   <groupId>ch.qos.logback</groupId>   <artifactId>logback-core</artifactId>   <version>1.1.8</version></d

Log4cpp配置文件及动态调整日志级别的方法

一.log4cpp概述 Log4cpp是一个开源的C++类库,它提供了C++程序中使用日志和跟踪调试的功能,它的优点如下: 提供应用程序运行上下文,方便跟踪调试: 可扩展的.多种方式记录日志,包括命令行.文件.回卷文件.内存.syslog服务器.Win事件日志等: 可以动态控制日志记录级别,在效率和功能中进行调整: 所有配置可以通过配置文件进行动态调整: 多语言支持,包括Java(log4j),C++(log4cpp.log4cplus),C(log4c),python(log4p)等: 二.原

[转载]log4j输出日志级别控制

我们知道:log4j.logger.XX cover ==> log4j.rootLogger log4j.appender.XX.Threshold决定了最低接收级别 也就是说rootLogger首先决定所有log的输出级别,而log4j.logger.XX是对XX路径下的jar包的输出级别的修改,直接覆盖rootLogger 但是对于不同的输出口,他们的接收级别是不同的. 举例1:log4j.appender.XX.Threshold门槛高于log4j.logger.XX时, log4j.l

自定义log4j日志级别

转载自:  http://blog.csdn.net/seven_cm/article/details/26849821 参考了网上资料:http://www.360doc.com/content/13/0527/11/10825198_288498671.shtml 因为项目中需要输出一些特别的日志来做数据统计.如果开启log4j提供的INFO日志级别,每天生成的日志文件就会变得越来越大.这样就得写个定 时任务来删除这个文件.为了只输出所需的日志级别,唯有自己定义一个log4j的级别,这样一来