如何使用Log4j2使用映射查找? [英] How to use map lookups using Log4j2?

查看:398
本文介绍了如何使用Log4j2使用映射查找?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找这三个网站如何使用log4j2创建一个地图查找(或任何其他查找):





我理解我正在阅读的一般想法,我只是有一段困难的时间把所有的位和块放在一起。



目标



为了能够放置某种变量,在log4j2.xml文件中,该文件在配置时或运行时将该变量替换为资源束中的值。这是我到目前为止:



配置文件 =https://i.stack.imgur.com/q2Sfc.pngalt =enter image description here>



查找类



>



getValue(key)方法在资源包中查找与该键相关联的电子邮件值。@Plugin名称是map,如果我已正确读取, .xml文件中也是map的前缀。所以,不会error.notification.emails得到传递到MapPropertiesLookup类中的lookup(String key)方法?

解决方案

是的,map是您查找的名称创造。因为Log4j已经有一个Lookup命名的映射创建另一个会导致问题。



是的,error.notification.emails应该作为键值传递给Lookup。假设getValue(key)工作,你的查找可能会工作,如果它被命名为别的东西。



然而,它可能更有意义,你提交一个Jira并要求ResourceBundleLookup,其中语法可以是:$ {bundle:bundleName:key}。当然,bundleName:key将被传递给查找作为键,它会将密钥分解为组件部分。



如果你还有其他问题,你可能考虑询问Log4j开发者邮件列表。


I have been looking over these three sites on how to create a map lookup (or any other lookup for that matter) using log4j2:

I understand the general idea behind what I am reading, I am just having a difficult time putting all the bits and pieces together.

Goal

To be able to place a variable, of some sort, in a log4j2.xml file that at configuration time, or runtime, replaces that variable with the values in a resource bundle. This is what i have so far:

Configuration File

Lookup Class

The getValue(key) method looks in a resource bundle for the email values associated with that key.The @Plugin name is "map" which, if i have read correctly, is related to prefixes in the .xml file that are also "map". So, wouldn't "error.notification.emails" get passed into the lookup(String key) method in the MapPropertiesLookup class? What do i need to do in order to get this to work?

解决方案

Yes, map is the name of the lookup you are creating. Since Log4j already has a Lookup named map creating another is going to cause problems.

Yes, error.notification.emails should be passed as the key value to the Lookup. Assuming that getValue(key) works your lookup would probably work if it was named something else.

However, it might make more sense for you to file a Jira and ask for a ResourceBundleLookup where the syntax could be something like: ${bundle:bundleName:key}. Of course, "bundleName:key" would be passed to the lookup as the key and it would split the key into the component parts.

If you have further problems you might consider asking on the Log4j developers mailing list.

这篇关于如何使用Log4j2使用映射查找?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆