viernes, 15 de mayo de 2015

Hazelcast Object Inspector

 I made a tiny class to inspect the objects inside the data grid of hazelcast. You can see all the objects in the distributed collection (maps, queues, list, etc).

Just download the sources from github https://github.com/carlgira/utils/tree/master/hazelcast-object-inspector add to the pom.xml the necessary dependencies from your application (if not you are going to get ClassNotFound exception when the application is trying to deserialize your objects).

Customize as you want the class.

Hope this will be helpful

viernes, 1 de mayo de 2015

Filter Weblogic Logs

This blog explains how to use a library that i develop, that captures and redirect information from the weblogic logs to any other medium.

The idea was to redirect the information of the proxy services log of the OSB (Oracle Service BUS), but it can be expanded to redirect logs of any kind of application that writes over the Weblogic server logs.

Note: Last year i wrote a blog about this same issue OSB Custom Proxy Logging  , but last time i used  log4j as default logging for weblogic and also use a superior version that the one installed on the server. One colleague told me to find a solution using as default the JDK logging and also not to change the version of the log4j on the server, to avoid problems with support . That's what i achieve with this.

Weblogic Custom Logging

This tool adds a custom handler to the Weblogic Server logger. That handler manages a list of Log4jManagers that filters the logRecords. I add two LogManagers to the lib; one that filters all the OSB messages and redirect them to a file, and another logManager that it's able to write a log for every Proxy Service configured.(You can also add your own custom logManagers to filter other applications)

To configure it, it's necessary to copy the library to the domain/lib, create and configure a startupClass in Weblogic, and finally add a log4j file with the configuration of the appenders and loggers.

The parameters needed to configure the startUpClass are:

1. Log4j.xml location
2. List of active LogHandlers

    /home/carlgira/soa-utils/weblogic-custom-logging/src/test/resources/log4j.xml   com.carlgira.weblogic.loggging.log4j.managers.MyLogManager1
com.carlgira.weblogic.loggging.log4j.managers.MyLogManager2
com.carlgira.weblogic.loggging.log4j.managers.MyLogManager3


You can download the source code from github.
https://github.com/carlgira/soa-utils


These are the detailed instructions:

1. Download and Compile the code

Download the maven project from github. You'll  have to change two things inside of the pom.xml

     1.1 Change the "mdw.path" variable with your environment path. 
     1.2 I test the tool with a 10.3.6 Weblogic, so maybe you'll have to change the name of the com.bea.core.logging jar.

2. Installation

2.1 Copy the generated file to the base_domain/lib folder.
2.2 Edit and copy your own log4j.xml file. In the project there is an example in src/test/resources

3. Create the startupClass

     3.1 In the Weblogic console go to "Startup and Shutdown Classess"


    3.2 Create a new Startup Class. Complete the parameters, and select the targets.
 
     Name: WeblogicCustomLog
     Class Name: com.carlgira.weblogic.loggging.WeblogicCustomLogging




     3.2  Go back to the to the StartupClass and edit the arguments. This time i will configure the OSBProxyLogManager.

Arguments:
 /home/carlgira/soa-utils/weblogic-custom-logging/src/test/resources/log4j.xml com.carlgira.weblogic.loggging.log4j.managers.OSBLogManager







     3.3 Save the changes

4. Create the Weblogic Filter


The tool only captures the logRecords and redirect them to other files. You'll have to manually create the log filters so the information won't be written on the weblogic logs.

     4.1 Go to your domain configuration and click on the "Log Filter" tab




    4.2 Create a Log Filter and edit them to add an expression. For the OSB i use a "MATCHES" operator.

   Message Attribute: MESSAGE
   Operator: MATCHES
   Value: (\[OSB\sTracing\]|\[Rastreo\sde\sOSB\])



    4.3 At the end the expression will look like this.



      4.4 Save all the changes
      4.5 Now it's time to apply the filter to the server. Go to the configuration of the server to the logging tab.




      4.6 Scroll down until the "message destination" and choose the WeblogicCustomFilter.



    4.7 Save all the changes
    4.8 Do this for every server you need to configure.

5. Check everything is ok

After all the changes, reboot your weblogic (the one that you configure as target in the StartupClass). If everything is ok, you will see a trace "weblogic-custom-logging, started".

6. LogManagers

LogManagers have to deliver the LoggerName. You can create a static LoggerName like is the case of the OSBLogManager or a dynamic one, like the OSBProxyLogManager does.

One thing that is VERY IMPORTANT is that those LoggerNames MUST be in the log4j.xml file so the tool knows where to write the filtered messages.

6.1 OSBLogManager

This is a simple class. It only has two attributes, one is the regex that filters the messages and the other one is the static loggerName.

You have to be sure to leave the "OSBServerLogger" in the log4j.xml file.



6.2 OSBProxyLogManager

This class has a more complicated behavior . It gets dynamically the name of the proxy service from the log message, but it must save the loggerName in the MDC of log4j (Is a temporary memory location to save shared variables inside of the executing thread) because not all the OSB proxy log messages brings the proxy name.

To make it work, you'll have to add manually the full name of the proxy service to the log4j.xml file, and replace every "/" for a "-" because the log4j cant detect those characters.




Log4j.xml File



That's all.

Thanks!