使用ESAPI记录器产生的日志[英] Logs generated using ESAPI logger

本文是小编为大家收集整理的关于使用ESAPI记录器产生的日志的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我在我的应用程序中使用 ESAPI 记录器.记录器 logger= ESAPI.getLogger(ABC.class)

在 ABC.java 类中,我们使用 INFO 级别来打印日志.根据定义,我们知道,Info 接受:

两个参数:info(Logger.EventType 类型,java.lang.String 消息)

三个参数:info(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)

我在我的应用程序中提供了两个参数:logger.info(EVENT_TYPE,msg);

生成的日志格式为:

[事件成功匿名:null@unknown->/com.sample.package.ABC][msg]

我想要这种格式的日志:

[事件成功][消息]

请告诉我如何删除由于 EVENT_TYPE 参数而打印的额外详细信息.

推荐答案

我们遇到了同样的问题,正在着手准备本周在 GitHub 上提交的 PR.

我们希望在发布后尽快提供反馈.

我们计划:

  • 添加两个属性:LogUserInfo 和 LogAppInfo(默认为 true)
  • 使用这些来决定我们是否要附加当前信息

记录器输出将是

    LogUserInfo=true and LogAppInfo=true: [EVENT SUCCESS Anonymus:null@unknown -> 
    /com.sample.package.ABC][msg]
    LogUserInfo=true and LogAppInfo=false: [EVENT SUCCESS Anonymus:null@unknown][msg]
    LogUserInfo=false and LogAppInfo=true: [EVENT SUCCESS /com.sample.package.ABC][msg]
    LogUserInfo=false and LogAppInfo=false: [EVENT SUCCESS][msg]

https://github.com/ESAPI/esapi-java-legacy/问题/527https://github.com/ESAPI/esapi-java-legacy/pull/529

我们知道这可以通过一些字符串格式模板和/或使用 MDC 进一步改进,但现在我们将尝试使 PR 尽可能简单,而不会造成潜在的安全问题或破坏功能.

本文地址:https://www.itbaoku.cn/post/1574966.html

问题描述

I am using ESAPI logger in my application. Logger logger= ESAPI.getLogger(ABC.class)

In class ABC.java, we are using INFO level to print logs. By definition we know, Info accepts:

Two args: info(Logger.EventType type, java.lang.String message)

Three args: info(Logger.EventType type, java.lang.String message, java.lang.Throwable throwable)

I have provided two arguments in my application: logger.info(EVENT_TYPE,msg);

Logs are generating in the format:

[EVENT SUCCESS Anonymus:null@unknown-> /com.sample.package.ABC][msg]

I want logs in this format:

[EVENT SUCCESS][msg]

Please tell me how can I remove the extra details which are getting printed because of EVENT_TYPE argument.

推荐答案

We faced the same issue and are working on a PR to be submitted on GitHub this week.

We would appreciate feedback on it as soon as published.

We plan to:

  • Add two properties: LogUserInfo and LogAppInfo (default to true)
  • Use those to decide if we are going to append the current information

The logger output will be

    LogUserInfo=true and LogAppInfo=true: [EVENT SUCCESS Anonymus:null@unknown -> 
    /com.sample.package.ABC][msg]
    LogUserInfo=true and LogAppInfo=false: [EVENT SUCCESS Anonymus:null@unknown][msg]
    LogUserInfo=false and LogAppInfo=true: [EVENT SUCCESS /com.sample.package.ABC][msg]
    LogUserInfo=false and LogAppInfo=false: [EVENT SUCCESS][msg]

https://github.com/ESAPI/esapi-java-legacy/issues/527 https://github.com/ESAPI/esapi-java-legacy/pull/529

We understand this could be further improved with some string formatting templates and/or using MDC, but for now we will try to make the PR as simple as possible without messing with potential security problems or breaking functionality.