• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help on logs parsing  RSS feed

 
Rishi Aggarwal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am new to java coding. so need suggestion on reading the log file using java code.

1) I wish to parse a file, and find a value for variable e.g. [StorageVersion].
2) After finding the value, it will be pushed to database.

Log File Path e.g. C:\\Temp\\test.txt"

Sample Logs :

{
//NAME
[1.2.2917] := s['3.4.454545'];

//Parameter
[1.2.2947] := s['1.2.56778'];

//Enabled
[1.2.3910] := B['22.43434.12232'];

//MAXCLOUMNNAME
[1.2.4217] := N['1.7.899982'];

//StorageVersion
[1.2.2917] := K['706146.0.22106932'];

}


From above log file, the Value i need is "706146.0.22106932"



Thanks in advance

Rishi
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a couple of questions I have first.

1) Is that as complex as the log file gets, or is it only ever a list of names (in form //NAME) immediately followed by the line with the value.

2) Is the String in the left hand square bracket important, or do you only want the String in the right hand square bracket.

Assuming that that is as complex as the file gets and you only ever want to map the name in the comment to the value in the right hand bracket I would:

* Loop through the contents of the file line by line, finding each instance of the names.

* When a name is found, read the following line and use a regular expression to extract the value in the right hand side square bracket. This will be simple if the logs are only ever in the format you show there.

* Store the name and the value in a Map, so you can look up the values using the name you want.

If the log file can have a more complex structure or you need other information from it then the approach I mentioned may not be the best.

Also, this isn't really a beginning Java question.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the issue you are facing? What did you try so far?

From the log file, it looks like it is pretty organized, so getting the value out should not be that complicated with respect to the parsing.
 
Rishi Aggarwal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies gentlemen.

To answers your questions :

- This log file is pretty straightforward, just a list of variables.
- String in the left is not important, as i just need a "//StorageVersion" value which is after := K[

I haven't tried anything yet.

Just i have basic knowledge of running a java program.

To be Honest, i was looking for the "code / regular expression" that be can be directly used. Sorry for passing on my work to you.

Regards
Rishi
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well no one is going to write the code for you. If that log file has a commonly used specification then there may be a library already written to parse it, but that seems unlikely.

As already mentioned, it doesn't look too complex so shouldn't be hard to parse. If you make an attempt and post your code here then someone will offer advice.
 
Rishi Aggarwal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is the code that i have written till now.



*************************
Sample Log File

{
//NAME
[1.2.2917] := s['3.4.454545'];

//Parameter
[1.2.2947] := s['1.2.56778'];

//Enabled
[1.2.3910] := B['22.43434.12232'];

//MAXCLOUMNNAME
[1.2.4217] := N['1.7.899982'];

//StorageVersion
[1.2.2917] := K['706146.0.22106932'];
}

************************

Help required :

1) I don't know what regular expression can i use.
2) I want a line to check that preceding line should have //StorageVersion .
3) n then i will check any string between := K[' and '];. From above log file "'706146.0.22106932'" is the value that i am looking for.

Thanks
Rishi
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this was my problem I'd write a lexer for this format. In my experience, such formats only ever tend to get more complex, and maintaining a handwritten parser leads to headaches. I wrote an introduction to lexers some years ago.
 
Rishi Aggarwal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Logs file will not become complex. Structure will remain the same and just the "StorageValue" keeps on chaging
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!