问题
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.
回答1:
That's not possible without rewriting that part of the library. There's currently no configuration controls for that.
Submit a PR to https://www.github.com/ESAPI/esapi-java-legacy
As project Co-Lead, I wouldn't entertain this on my own time.
回答2:
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.
来源:https://stackoverflow.com/questions/58928401/logs-generated-using-esapi-logger