Skip to Content
0

Logging properties customization for SAP HCP Java Application

Mar 19 at 10:42 AM

63

avatar image

Hi, Could anyone please suggest how to configure properly logging.properties file for SAP HCP Java application. What I want to achieve is adding new sections which I would like to log, but no any documentation among SAP HCP Wiki. I believe to do everything correctly I need to know initial logging properties which are used to output console records

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Ivan Mirisola
Mar 19 at 04:01 PM
0

Hi Nikolay,

Do you have SCP SDK installed on your Eclipse together with the Eclipse Plugins from SAP? If so, you are able to test your Java application locally, using the same runtime as you would find on SCP (i.e.: Tomcat 8 runtime). With that in mind, you can configure the logging via the runtime server you assign your application in Eclipse. Just double-click on the server configuration from the servers view and select the Loggers tab. Please take a look at mine:

Here I have set my package to be logging DEBUG information. Notice that the server configuration is local, so once you save it, it will be stored on the logging.properties file located on the "servers" folder of your eclipse as a "project". Please note that the loggers will only be displayed whenever your server is started. So add you application to the server and start it before trying to configure anything.

Once you are satisfied with the config, you can use the logging properties file on SCP.

To be able to log messages on the default trace files you can stick with slf4j log factory, just like this:

Log messages will appear like this:

Regards,
Ivan


log-config.jpg (33.5 kB)
code-logging.jpg (58.6 kB)
log-messages.jpg (94.2 kB)
Show 11 Share
10 |10000 characters needed characters left characters exceeded

Hi Ivan, thanks for your response. Unfortunately, I don't have eclipse. I'm using spring boot and able to set the level of logging for any logger and also I'm able to change output pattern adding such property to application.properties file

logging.pattern.console=[%d{dd-MM-yyyy HH:mm:ss.SSS}] %highlight([%-5level]) %highlight(%logger{36}.%M) %green(%X{clientSessionId}%X{clientRequestId}) %highlight(%msg%n) 

But console patter changing takes affect only when web server is deployed locally, when I deploy it to SAP HCP then nothing changed in HCP console, so I believe that I need to have logging.properties file which contains correct logging configuration. If you have such example which is suitable for SAP HCP then I would appreciate your help.

0

My issue could be solved also if there is any way to put data into "Transaction" and "Counter" columns or to add new custom columns

0

You might want to try setting the root loggers to INFO instead of ERROR. Then set your package to DEBUG.

The file "logging.properties" is a Spring "thing" - not a feature you are able to configure in Neo.

I have never deployed a Spring App on Neo. I will give it a try later on and let you know my findings...

0
0
Nikolay Androsovych

Hi Nikolay,

I have managed to successfully show messages in the Cockpit default trace file.
I've made a git repository for your convenience and testing.

Spring Boot Logger

But basically all you really need is to set the pom.xml file properly to avoid conflicting libs from Spring that are already provided by the Neo runtime. Check my pom.xml to see how this can be accomplished.

Once your app runs perfectly on SCP Neo, you can configure the log settings on your application.settings like so:

logging.level.org.springframework=info
logging.level.org.apache=ERROR
logging.level.com.imirisola.spring.logger=TRACE
logging.pattern.console=%d{HH:mm:ss.SSS} %-6level %logger{72} - %msg%n

I've used Lombok for convenience, but you could use a static variable on your class with the getLogger method of org.slf4j.LoggerFactory.

I couldn't quite figure out a logback example for you. But I believe this one will suffice.

Please note that there is a huge difference between Neo and Cloud Foundry. One of the links you found relates to CF where there is a dependency to a lib that is specific to CF. I believe it won't work with Neo at all.

If you switch to a CF landscape, than please review the documentation for logging on GitHub.

Regards,
Ivan

0

Hi Ivan, big thanks to you for your effort. Actually, I have already exactly the same what you are proposing. But unfortunately, logging.pattern.console does not make any effect on logs which are recorded when an application is deployed on HCP. For example, you have something that you put to MDC context logging.pattern.console=%d{HH:mm:ss.SSS} %-6level %logger{72} %X{userSessionId} - %msg%n and when you will check your logs in HCP cockpit then you will not see anything related to userSessionId. It takes effect only when you are deploying to the local tomcat server. The reason why I want to output this userSessionId is for tracking log records related to the session of a user which is logged.

Thanks again, really appreciate your helping

0
Nikolay Androsovych

Hi Nikolay,

Do you mean you don't see the userSessionId on the log viewer or on the file itself?

I ask you this, because on my logs I am able to see the user id information like so:

2018 03 21 18:39:58#+00#TRACE#com.imirisola.spring.logger.Hello##anonymous#https-jsse-nio-8041-exec-7#na#i807056trial#springbootlogger#web#i807056trial#na#na#na#na#Hello me... meet the real me!  |

So it is clear to me that user logged on as anonymous. I understand that session id will allow you to track how many times you are seeing the same user logging on to your app. Is this what you are trying to track?

Regards,
Ivan

0

It is my custom session id. It is not presented either in the viewer nor in the log file. By the way, the above example of the log record provided by you shows that your pattern %d{HH:mm:ss.SSS} %-6level %logger{72} - %msg%n was not applied

0

If you have any connection with developers of SAP HCP, please, suggest them to add the ability to change pattern layout for applications which are deployed on SAP HCP Neo Env. It is the really important feature for all applications which serve user's requests parallely.

0
Nikolay Androsovych

Hi Nikolay,

You could do it yourself. Open the Customer Influence and record your idea there.

Just one thought: the cockpit will display the columns based on the standard log format. If you have a different format, you need to download the logs to be able to see all the data being recorded. I would not expect SCP developers to make the log viewer app dynamic - according to the log columns being read.

But if this is an absolute *must*, you could share your idea on the customer influence and try to get others to vote on your idea. Then, developers may take this into account when the improove the apps in the cockit.

Regards,
Ivan

1

Thanks for the idea, will do it

0
Ivan Mirisola
Mar 27 at 09:22 PM
0

Hi Nikolay,

Good news and bad news.

The good news is that it is possible to log other data into the log files and have access to them via cockpit. The bad news is that you cannot use any of the standard methods known in Spring and it is not as easy as it sounds.

I've discussed this topic with several internal colegues and here are my findings:

(1) Neo completely replaces any log facility you have on Spring - including logback, log4j, slf4j, etc.

(2) For additional logging formats, you must implement your own log facility that writes log entries at the following location: "/usr/sap/ljs/log" and the filename must be "application.log"

(3) Variables must have the separator "#" - so you cannot write anything with commas, spaces or dashes.

(4) Your log file will have last execution priority in the tread model. Therefore, your entries will be placed in the cockpit long after the application interaction.

(5) Your log entries will appear in the cockpit as "Other Logs" and once you click to download it, the file name should be in the format of "application_<PID>_<date>.log"

(6) Session ID and User Principal information can be retrieved either via javax.servlet.http.HttpServletRequest or java.security.Principal - so you need to capture that info before writing it to the log file.

I have modified my spring boot logger app to include Spring Security (very basic) so I could capture the user details and the session id onto the logs.

Regards,
Ivan

Share
10 |10000 characters needed characters left characters exceeded