将System.out.println重定向到Log4J,同时保留类名称信息(Redirect System.out.println to Log4J, while keeping class name information)
我有一些库在调用System.out.println,我想通过log4j或commons logging重定向它们。 但特别是我想保留完全限定的类名,以便我知道哪些组件生成了日志。
有没有一个很好的,有序的方式来实现这一目标?
更新:完成后,我在这里发布代码:
http://www.bukisa.com/articles/487009_java-how-to-redirect-stderr-and-stdout-to-commons-logging-with-the-calling-classI have some libraries that are calling System.out.println on me, I'd like to redirect them through log4j or commons logging. But in particular I'd like to keep the fully-qualified-classname so I know what component generated the logs.
Is there a nice, orderly way to accomplish this?
UPDATE: After accomplishing this I posted the code here:
http://www.bukisa.com/articles/487009_java-how-to-redirect-stderr-and-stdout-to-commons-logging-with-the-calling-class
原文:https://stackoverflow.com/questions/5712764
最满意答案
鉴于w3c模式文档中的以下句子:
假定“本地”或未定时的时间是由适当的法定机构规定的某个未指定地点的时区;
和
将时区添加到UTC dateTime时,结果是“在该时区内”的日期和时间。
这听起来不像是有一个明确的答案 。 我认为这通常是模棱两可的:两种版本都是基本有效的,使用哪个版本的问题取决于与系统连接的系统的配置/行为/期望。
即使有明确的答案,我也绝对不会依赖它,而是期望每个其他的Web服务和图书馆都有自己的方式来处理这个问题:
Given the following sentences from the w3c schema documentation:
"Local" or untimezoned times are presumed to be the time in the timezone of some unspecified locality as prescribed by the appropriate legal authority;
and
When a timezone is added to a UTC dateTime, the result is the date and time "in that timezone".
it does not sound like there is a definitive answer to this. I would assume that it is the usual ambiguity: Both versions are principally valid, and the question of what version to use depends on the configuration/behavior/expectations of the system one is interfacing with.
And even if there where a definitive answer, I would definitely not rely on it, but rather expect that every other web service and library had its own way of dealing with this :/
相关问答
更多-
无论本地时区如何,都可以获取另一个时区的日期时间(Get DateTime For Another Time Zone Regardless of Local Time Zone)[2021-06-11]
正如所有人都提到的,.NET 2不包含任何时区信息。 尽管信息存储在注册表中,并且在它周围编写一个包装类是相当微不足道的: SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Time Zones 包含所有时区的子键。 TZI字段值包含时区的所有转换和偏置属性,但它都填充在二进制数组中。 最重要的位(偏置和日光)分别是存储在位置0和8的int32s: int bias = BitConverter.ToInt32((byte[])tzKey.GetVal ... -
如何将带有时区的PostgreSQL时间戳转换为DateTime?(How to convert PostgreSQL timestamp with time zone to DateTime?)[2022-07-04]
这里有一个真正的乔达答案。 你有没有尝试org.joda.time.format.DateTimeFormat以下模式? “yyyy-MM-dd HH:mm:ssZ” 我看到您的时区偏移量仅以小时而非分钟指定。 所以也许你需要简单的预处理和双Z这样的: String psqlDate = "2013-11-17 14:08:33+01"; DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ssZZ"); Dat ... -
令我惊讶的是,它似乎确实如此。 web81:~/webapps/dominicrodger2/dominicrodger$ python2.5 manage.py shell Python 2.5.4 (r254:67916, Aug 5 2009, 12:42:40) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2 Type "help", "copyright", "credits" or "license" for more information ...
-
Django和时区(Django and time zone)[2022-07-09]
基本上发生的情况是时间使用时间戳存储在数据库中,但使用数据库中指定的时区显示时间,除非手动更改是机器的时区。 但是由于你在django中指定了一个不同的时区,django会调整差异。 所以你需要做的是将db中的时区更改为UTC(进程因引擎而异) 我喜欢这样做的方法是保持数据库时区不变,在django设置中指定'UTC',然后每当向用户显示时间时,使用一些javascript将其转换为本地用户时间。 编辑 之前没有注意到你正在使用PostgreSQL。 我想你可以在postgresql.conf中更改时区或在 ... -
从DateTime获取时区(Get timezone from DateTime)[2022-10-31]
DateTime本身不包含实时的时区信息。 它可能知道是UTC还是本地,但不是当地的真正意义。 DateTimeOffset有点好 - 这基本上是UTC时间和偏移量。 然而,仍然不足以确定时区,因为许多不同的时区可以在任何一个时间点具有相同的偏移量。 这听起来好像对你来说可能还不错,因为在解析日期/时间时所有的工作都是偏移。 对.NET 3.5的时区的支持比它好多了,但是我真的很想看到一个标准的“ZonedDateTime”或者这样的时间 - 一个UTC时间和一个实际的时区。 很容易建立自己的,但是很高兴在 ... -
应该在dateTimeTime元素中包含SOAP消息中的时区信息吗?(Should dateTime elements include time zone information in SOAP messages?)[2023-08-13]
鉴于w3c模式文档中的以下句子: 假定“本地”或未定时的时间是由适当的法定机构规定的某个未指定地点的时区; 和 将时区添加到UTC dateTime时,结果是“在该时区内”的日期和时间。 这听起来不像是有一个明确的答案 。 我认为这通常是模棱两可的:两种版本都是基本有效的,使用哪个版本的问题取决于与系统连接的系统的配置/行为/期望。 即使有明确的答案,我也绝对不会依赖它,而是期望每个其他的Web服务和图书馆都有自己的方式来处理这个问题: Given the following sentences from ... -
你能不能使用非关联数组? 即 'interfaceFields' => array ( array ('Name' => 'master_id', 'Value' => '0' ), array ('Name' => 'Name', 'Value' => 'jansen' ), array ('Name' => 'birthdate', 'Value' => ' ' ), array ('Name' => 'add_id', ' ...
-
转换缺少时区的时间(Convert times with missing time zone)[2022-02-03]
请试试这个: select DateTime.Parse(el).ToUniversalTime() Please try this: select DateTime.Parse(el).ToUniversalTime() -
目前,MQ WCF自定义通道仅支持SOAP消息,不支持非SOAP消息。 MQ WCF自定义通道查找特定的邮件头,以将传入邮件标识为WCF邮件。 如果这些头不存在,将抛出WCFCH0314E异常。 Currently MQ WCF custom channel supports only SOAP messages, no support for non-SOAP messages. The MQ WCF custom channel looks for specific message headers to ...
-
所以经过一段时间的研究和试验和错误之后,我设法解决了我的问题。 我使用wireshark来检查Onvif Device Manager应用程序发送到相机的内容,并最终收到以下消息:
相关文章
更多- Log4j 随笔
- Solr 使用 Log4j
- Log4j 记录Log日志
- 问个log4j的应用一个问题。
- 请教:log4j 问题
- LOG4J的配置
- log4j配置日志输出到文件
- Log4J 详细注释版收藏
- log4j配置日志输出到数据库
- log4j快速入门示例
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。