【问题标题】:Using type tag in logback configuration for logback-elasticsearch-appender在 logback-elasticsearch-appender 的 logback 配置中使用类型标签
【发布时间】:2018-07-17 19:19:49
【问题描述】:

正如每个人都可以在他们的GitHub page 中看到的那样,property 标记有一个内部 type 标记,它应该告诉 Elasticsearch 是否应该写入该属性的值作为字符串,数字...在生成的 JSON 中(至少我是这么理解的):

type(可选,默认字符串):结果字段的类型 JSON 消息。可能的值有:String、int、float 和 boolean。

但我不能让它工作。

这是我的 logback.xml 文件的 sn-p:

<appender name="ELASTIC" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
...
    <property>
        <name>elapsed time (ms)</name>
        <value>%X{elapsedTime}</value>
        <type>int</type>
    </property>
...
</appender>

我正在使用 JoranConfigurator 配置 logback:

String logConfigurationPath = "logback.xml";
if (logConfigurationPath != null) {
  LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

  try {
    JoranConfigurator config = new JoranConfigurator();

    config.setContext(context);

    context.reset();

    config.doConfigure(logConfigurationPath);
  } catch (JoranException je) {

  }
  StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}

Logback 配置正常,但是当它尝试处理该 type 标记时出现错误:

testingdocker                | 09:46:13,134 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@68:23 - no applicable action for [type], current ElementPath  is [[configuration][appender][properties][property][type]]

Elastic 在生成的 JSON 中将该标签设置为字符串,我可以在 Kibana 中进行检查。

如何正确使用该标签,以便从 Logback 获取 Kibana 中的数字类型?

【问题讨论】:

    标签: java elasticsearch kibana logback


    【解决方案1】:

    这似乎是appender中的一个错误。

    如果你看到 Property.java,你会看到:

    public void setType(String type) {
        try {
            this.type = Enum.valueOf(Type.class, type.toUpperCase());
        } catch (IllegalArgumentException e) {
            this.type = Type.STRING;
        }
    }
    

    所以,如果你设置的东西不在 Enum 中,它将使用 String。这可以。所以我们可以看到关于Type:

    public enum Type {
         STRING, INT, FLOAT, BOOLEAN
    }
    

    我认为你有问题! ElasticSearch 不接受“int”类型,而是“integer”。

    有关数据类型的更多信息:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多