sofastack / sofa-common-tools Goto Github PK
View Code? Open in Web Editor NEWsofa-common-tools is a library that provide some utility functions to other SOFA libraries.
License: Apache License 2.0
sofa-common-tools is a library that provide some utility functions to other SOFA libraries.
License: Apache License 2.0
If multiple logger factories with the same namespace will get multiple log-conf
files for the classpath. We need to add the order to the configuration files to determine the priority.
sofa-common-tools's purpose is to address the concern of logging, but the logging of itself has problems.
Some of its classes needs to log too, while they use SLF4j whose configuration depends on user (which is absolutely hilarious). In general, users don't even know the issue, so the logs are all printed to stdout.
Add a contribution guide and update the readme.
When read config properties in jar file will get FileNotFoundException , priority set to log config will not work.
java -version
): 1.6uname -a
): linuxA clear and concise description of what the bug is.
java -version
):uname -a
):@guanchao-yang 您好,框架动态日志级别修改的测试类可以提供一个 在方法级可动态改变此日志的级别
Right now if the application class path does not contains a well-known logging backend (like Logback, Log4j and etc) the created logger gets fixed predefined name "com.alipay.sofa.common.log".
So if an app uses a library like SOFAJRaft and uses a not very popular Slf4j-compatible logging backend (for example, GFLog) then all logging that is produced by that library gets default logger name "com.alipay.sofa.common.log". As result, it is impossible to control logging levels of different parts of the library separately.
Example:
Logger log = LoggerSpaceManager.getLoggerBySpace("someLoggerSpace", "someLoggerName");
// Returns logger with name "com.alipay.sofa.common.log".
// "someLoggerSpace" or "someLoggerName" are not included into the logger name at all
We need to control logging levels for different parts of the app separately because logs from different parts have different importance levels even if there is no logging backend known by sofa-common-tools.
I think its necessary to modify MultiAppLoggerSpaceManager.NOP_LOGGER_FACTORY
to actually take in account provided logger name instead of just defaulting to a Constants.DEFAULT_LOG
:
private static final AbstractLoggerSpaceFactory NOP_LOGGER_FACTORY = new AbstractLoggerSpaceFactory(
"nop") {
@Override
public Logger getLogger(String name) {
return LoggerFactory.getLogger("com.alipay.sofa.common.log." + name);
}
};
Ideally it would be nice to also take the space into the account but for that it would be necessary to modify MultiAppLoggerSpaceManager
to create new instances of AbstractLoggerSpaceFactory
instead of using single NOP_LOGGER_FACTORY
if no pre-defined logging backend is found.
Alternatively, it would be nice to have support of custom logging backend so it would be possible to utilize other logging backends that are not explicitly mentioned in MultiAppLoggerSpaceManager.createILoggerFactory(...)
jraft-core:1.3.9
)java -version
): openjdk version "11.0.13"When used as Spring bean, property setter method is called before init method (bean lifecycle). Thus, executor is null when calling threadPoolName's setter method, which results to NPE.
getClallerClassLoader will try tccl first to load class.
However, in multi-classloader environment, above behavior will get the initial class loader not the caller classloader
As we all known, ExecutingRunnable is an wrap of Runnable which were used as tracking the running info of submited tasks.
but we can't not access ExecutingRunnable directly due to it's packge level access.
when we making custom excutor extends SofaThreadPoolExecutor or making custom workQueue for the excutor,
we need access to origin Runnable so we can read infomation in our own custom Runnable.
Add Public Access Modifiers to ExecutingRunnable
java -version
):uname -a
):When application started in IDE,error occurs during bootstrap and the error log output like common-error.log
.When the commponents are too more ,the error output to file not easy to find。So, providing a mechanism for guaranteeing error log output in console when run in IDE for better experience
您好,继续咨询几个问题:
1.假如我们现在的业务系统中已经引入了三方包,三方包用log4j打印的,我们业务系统准备用logback打印日志,那是说我们的业务系统要用sofa-common-tools打印日志吗?还是要求三方包改用这个框架打印日志?
2.假如好几个三方包有的用log4j打印日志,有的用logback打印日志,怎么解决他们的冲突问题?三方包我们无法要求别人修改代码了.
3.日志隔离的具体应用场景是什么那?我们的业务系统虽然引入了很多三方包,但是也没出现过日志冲突的问题,或者出现了我们可以通过调整配置也能解决他们冲突的问题,实现三方包和我们的业务系统同时打印日志.
4.动态日志级别的具体应用场景是什么那?感觉平时也用不到啊?
describe your question clearly
describe your use scenes (why need this feature)
describe the advice or solution you'd like
java -version
):uname -a
):Can't change root logger level for Log4j
LoggerSpaceFactory4Log4jBuilder # setLevel()
MayBe use ?
repo.getRootLogger().setLevel(this.toLog4jLevel(adapterLevel));
java -version
):uname -a
):Currently all the log will print to the corresponding log file when running application in the IDE, which make it inconvenient to find the log.
The only way to print all the log into the console is set a VM option -Dsofa.middleware.log.disable=true
We should provide a more convenient way to provide the ability to log all the file into the console.
ThreadPoolExecutor has no built-in ability of logging for decayed tasks. Hope for there are:
Also, Spring's ThreadPoolTaskExecutor is also used widely, it's appreciated if this ExecutorService is also supported.
怎么配置的先用logback 还是log4j这种的?不太明白 能否解答一下
I seems a bug that only error log can be logged in console when config sofa.middleware.log.console with implementation of log4j2
public AbstractLoggerSpaceFactory doBuild(String spaceName, ClassLoader spaceClassloader,
URL url) {
return new LogbackLoggerSpaceFactory(getSpaceId(), new LoggerContext(), getProperties(),
url, getLoggingToolName());
}
should use spaceClassloader load LogbackLoggerSpaceFactory class.
该组件提供了修改日志级别的接口,我们准备对接自己的配置中心实现日志等级的动态配置,想咨询下你们是如何使用该组件实现的,未来是否会提供类似的功能比如对接一些配置中心比如zookeeper或者 Apollo Nacos 等
您好,如下代码,然后两个问题是 SpaceId这个设置之后是和配置文件相对应的么,可以再加SpaceId怎么设置,这个场景是,那个动态日志级别是否是我代码中那个意思呢,感谢并期待您的回复
`/**
* SpaceId这个是自己规定的一个规范名字 可以理解为自己的日志空间
*/
public static final String SHOW_LOG_SPACE = "com.alipay.sofa.rpc";
/**
* 可动态改变日志级别的打日志方法
*
* @param name 一般类名
* @param adapterLevel 日志级别 info debug等
* @return
*/
public static Logger getLogger(String name, AdapterLevel adapterLevel) {
//这个是控制是否采用logback日志 true是关闭此日志用下个日志
System.setProperty(Constants.LOGBACK_MIDDLEWARE_LOG_DISABLE_PROP_KEY, "true");
//可以动态改变日志的级别
return LoggerSpaceManager.setLoggerLevel(name, SHOW_LOG_SPACE, adapterLevel);
}`
你好,请教给问题,rt,我不太明白这两个类实现的目的是什么?
No need for separate directory, only log4j.xml, log4j2.xml and logback.xml is enough
com.alipay.sofa.common.boot.logging.CommonLoggingApplicationListener#reInitializeLog 方法中,入参 map 的一个 key 为sofa.middleware.log.disable
,运行到第74行时,实际上是:
int index = Constants.SOFA_MIDDLEWARE_CONFIG_PREFIX.length();//20
int end = "sofa.middleware.log.disable".length() - 9;//19
key.substring(20, 19)
然后就报错了
java -version
):uname -a
):It is used in SofaThreadPoolExecutor.
Log4j2 initializer config error properties of Log4j2 ThreadContext, if log4j2 config file contains ${ctx:var}, it would lead initialization of Log4j2
See the above picture as an example, the package in the log should be the package that print the log, not com.alipay.sofa.common.log
.
add -Dsofa.middleware.log.disable=true
to the VM options to reproduce the bug.
java -version
):uname -a
):重构了线程池相关实现,将线程池的监控、配置等能力抽象到了公共类中,以便支持其它类型的线程池
@Override
protected void beforeExecute(Thread t, Runnable r) {
executingTasks.put(r, new RunnableExecutionInfo(t));
super.beforeExecute(t, r);
}
This method not support the situation that r
running in different t
.
Some dependencies in child module have not use dependencyManagement to inherit version
根据 sofa-common-tools 的规范对常用日志实现(Logback、Log4j2 和 Log4j)均进行配置(配置日志输出文件和格式),当应用引入二方包或者中间件时,根据应用中已有的日志实现并选择该日志实现能够正确解析的配置文件来初始化完成二方包或者中间件的日志配置来完成日志的输出,并同时不会和某一个具体日志实现绑定。从而完成在不用业务配置额外的 appender 和 logger 或者业务不用修改任何配置的情况下,完成日志空间打印的隔离能力。
疑问1:
中间件或二方包引入什么日志框架,并不会影响到应用的的日志打印呀。
应用引入中间件或二方包,并不一定需要进行appender和logger配置的修改。
这些都可以通过slf4j提供的桥接包,或者log4j2提供的桥接包(log4j->log4j2)解决。
既然不影响,为什么要用sofa-common-tools包,将简单的问题搞复杂了。
疑问2:
“完成日志空间打印的隔离能力“
这里的空间隔离是指?是指打印到不同的日志文件?
如果是的话,这个完全可以通过将logger配置成包名,再配置相应的appender的方法解决。
Now, we can set -Dlogging.level.com.alipay.sofa.rpc=WARN
to specify the log level of com.alipay.sofa.rpc
.
Can we provider a global switch like logging.level.com.alipay.sofa.*=WARN
to set log levels of all log namespace.
related with #53
对于三方包, 如何重定向依赖的三方包的日志输出?
我目前在开发一个中间件, 因为日志问题, 所以希望引入sofa-common-tools. 不过遇到一个问题. 我的中间件引入了其他的三方包, 一开始我是通过自定义appender将它的日志重定向到了希望的文件下, 但是引入了sofa-common-tools后发现重定向失败了. 我想这是和sofa-common-tools中所有logger必须通过自定义的LoggerFactory类来获取有关. 而且去改造引入的三方包是不可能的. 请问有什么好的解决方案?
com.alipay.sofa.common.log.LoggerSpaceManager#getLoggerBySpace(java.lang.String, java.lang.String) as follow:
public static Logger getLoggerBySpace(String name, String spaceName) {
return getLoggerBySpace(name, new SpaceId(spaceName),
Collections.<String, String> emptyMap());
}
In order to support sofa ark environment, we should use caller classloader default.
Now binding message of log implementation is reported to used system.print. An internal Logger is recommended to use instead.
As JDK and SOFABoot evolves, SOFABoot has already end the support of JDK 6, it's time to terminate the support of JDK 6.
Before some alipay users use ReportUtil
with the full package com.alipay.sofa.common.log.ReportUtil
but in this version ReportUtil
has been moved to com.alipay.sofa.common.utils.ReportUtil
. Consider many users has used, so we should be compatible with it
com.alipay.sofa.common.log.env.LogEnvUtils.processGlobalSystemLogProperties use System.getProperties().entrySet() in Iterator
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.