Page 1 of 1

Sample for Read from Systemlogger via ZLogstream

PostPosted: Wed Aug 30, 2017 1:10 pm
by SPelzet
Hi there,

I'm trying to read (browse) from a Systemlogger with Java. I found the wrapper Class ZLogstream. But there is no sample from IBM how to read with this class.
Can someone give me a sample, which makes things such easier for me?

I found out, that the constructor makes a Connection to the Logstream. But how should I go on..? Thanks in advance.

Re: Sample for Read from Systemlogger via ZLogstream

PostPosted: Thu Aug 31, 2017 1:46 am
by Robert Sample
To make a connection to a logstream, you MUST know the name of it. How do you find the name? Since each and every site can define its own logstream name, you have no choice but to contact your site support group and find out the name of your site's logstream. Then you connect to it, assuming you have appropriate security, and then use the appropriate method to search / browse / whatever the logstream.

Re: Sample for Read from Systemlogger via ZLogstream

PostPosted: Thu Aug 31, 2017 1:19 pm
by SPelzet
Well the connection is not the problem. I know the name of the Logstream and yes the connection is successful.

Look at my source


    //get Timestamp
        long unixTimestamp = Instant.now().getEpochSecond();
        RecordReader reader=null;
        int bytesRead =0;
       
        System.out.println("Hallo Welt");
        ZLogstream myStream = new ZLogstream("MTLOGGER.TEST.MTPPS");
        //get Maxium Buffer
        byte[] buffer=new byte[myStream.getMaxBlockLength()];
        myStream.browseStartSearch(false,unixTimestamp);
        bytesRead=myStream.readSearch(unixTimestamp, buffer, 0);       
 


My problem here is that I get no useful information in the Field 'buffer'. In the debugger I values such 0, -15 or something like that. But not printable value, which I can cast to characters.

What should I do here?

Re: Sample for Read from Systemlogger via ZLogstream

PostPosted: Thu Aug 31, 2017 6:19 pm
by Robert Sample
I see in the manual that getMaxBlockLength() is returning an int value -- what happens when you look at the int value?

Here's an article on using Zlogstream (page 15): http://publibz.boulder.ibm.com/epubs/pdf/e0z2n1a1.pdf

Re: Sample for Read from Systemlogger via ZLogstream

PostPosted: Fri Sep 01, 2017 3:02 pm
by SPelzet
Thanks for the link. Very interesting :) But unfourtanely there is only described the write Method. The Browse Feature in this class is fairly new..


Anyway - I refactored my code and now I get an output - but I read only the same record. How could I read the logstream record by record? Not even Block by Block. The documentation is not really helpful....

public class mtbr01 {

    public static void main(String[] args) throws IOException {
       
        try{
        //Log Stream name
        String logName="MTLOGGER.TEST.MTPPS";
        byte[] buffer=new byte[1000000];
        //get Timestamp
        long unixTimestamp = Instant.now().getEpochSecond();
        int bytesRead =0;
        //Open and connect to LogStream (MTLOGGER.TEST.MTPPS)
        ZLogstream zlogger = new ZLogstream(logName);

        zlogger.browseStartSearch(false,unixTimestamp);
       
        for(int i=0;i<10;i++){
        bytesRead=zlogger.readSearch(unixTimestamp, buffer, 0);
        String value = new String(buffer);
        System.out.println("Satz Nummer"+i);
        System.out.println(value);
        }
   
    }
   
    catch(ZLogstreamException EX)
    {
        //Print out messages and return codes from the logger
        System.err.println("System logger error message <" +EX.getMessage() + ">");
        System.err.println("System logger ReturnCode/ReasonCode <"+ EX.getReturnCode() +"/" + EX.getReasonCode() +">");
        System.err.println("System logger resource <" + EX.getLogstreamName() + ">");
        //Print out Java stack trace
        EX.printStackTrace();
        return;                                            
    }
        }

}