Win a copy of The Java Performance Companion this week in the Performance forum!
    Bookmark Topic Watch Topic
  • New Topic

Does anyone know how to read a log file in .log and output the data using java language ?

 
motress zlting
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
Does anyone know how to read a log file in .log and output the data using java language ?
Please help me !!!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12147
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
What do you mean? What is ".log"? is that a language? a file format? Why can't you read it like any other file in java?

 
Mazer Lao Tzu
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Report post to moderator
".log" is simply a common file extension indicating that a particular file serves as a log for a particular application. Most likely these files are written in ASCII, but the format in which they represent data is entirely dependent on the application that wrote the file.
What application wrote the file?
 
motress zlting
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
fred rosenberger wrote:What do you mean? What is ".log"? is that a language? a file format? Why can't you read it like any other file in java?


It is a text file with the extension .log which contains data inside.
Where can i find the coding to read the data in .log file and display it ?
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Report post to moderator
If it is just a plain text file with a .log extension, you should just be able to use the same code that you would use to read a regular .txt file.
 
motress zlting
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
Mazer Lao Tzu wrote:".log" is simply a common file extension indicating that a particular file serves as a log for a particular application. Most likely these files are written in ASCII, but the format in which they represent data is entirely dependent on the application that wrote the file.
What application wrote the file?

Accuatly the log file is created using placelab (an open source to detect wireless signal). Its detect all wireless ap signal strength in a particular area and save it in log file.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Report post to moderator
Is there any reason to display it with Java? Can't you just use the command line or an editor?
 
motress zlting
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
TYPE=TIMEOUT
TYPE=WIFI|TIME=1263867778390|ID=00:24:c3:31:2b:e0|NAME=csusm|RSSI=-93|WEP=true|INFR=true
TYPE=WIFI|TIME=1263867778390|ID=00:12:17:7b:33:04|NAME=csusm|RSSI=-80|WEP=true|INFR=true
TYPE=WIFI|TIME=1263867778390|ID=00:1f:27:55:f7:70|NAME=USMHotspot|RSSI=-70|WEP=true|INFR=true
TYPE=WIFI|TIME=1263867778390|ID=00:1e:13:ee:3e:40|NAME=USMHotspot|RSSI=-85|WEP=true|INFR=true
TYPE=WIFI|TIME=1263867778390|ID=00:24:c3:31:b8:80|NAME=csusm|RSSI=-91|WEP=true|INFR=true


The above is part of the log file data which contain the type of wireless ap, time detected, Id, name of wireless ap, signal strength and so on.
But i just want to read the signal strength, count the signal average and display it.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12147
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
Can you write a java program to open and read any file? There is nothing special about it being a '.log' file.

[edit]
So now we're getting what you really want. You still need to be able to do the above. I'd suggest you write a program that reads each line and prints it out first. Once you have that, you can start looking at parsing the data. The best way to do this is by writing a little piece at a time.

 
motress zlting
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
fred rosenberger wrote:Can you write a java program to open and read any file? There is nothing special about it being a '.log' file.

[edit]
So now we're getting what you really want. You still need to be able to do the above. I'd suggest you write a program that reads each line and prints it out first. Once you have that, you can start looking at parsing the data. The best way to do this is by writing a little piece at a time.



Now i can read the file and display it. Thank to all.
But the problem i faced now is how am i gonna just read the signal strength RSSI ? I don wan to display other info, just want to display the signal strength.
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Check out String.split, but take into account that | means something special when used as an argument to String.split.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12147
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
you could also find where in the string "RSSI" is, and then you can grab the 2-character substring just a few places after that...
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Ehm, that's not necessarily 2 characters. It may also be 3, like -90.

You do have a point however. Using indexOf you can first find where RSSI= starts, and advance to the end of that. Next find the next |, and take the substring in between.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12147
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
since all the examples had the '-', it didn't matter. but that is a good point. Could you have 3-digit or 1-digit values? or 4-digit?

the larger point is there is more than one way to do it.
 
motress zlting
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
fred rosenberger wrote:since all the examples had the '-', it didn't matter. but that is a good point. Could you have 3-digit or 1-digit values? or 4-digit?

the larger point is there is more than one way to do it.


largest is 3 digit such as -90 .
 
motress zlting
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
Rob Prime wrote:Ehm, that's not necessarily 2 characters. It may also be 3, like -90.

You do have a point however. Using indexOf you can first find where RSSI= starts, and advance to the end of that. Next find the next |, and take the substring in between.


But the indexOf() is just use to show the location of the character and printout the location number.
How can i make it to take the -90 and print it out ?
 
Henry Wong
author
Marshal
Pie
Posts: 21212
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
motress zlting wrote:
But the indexOf() is just use to show the location of the character and printout the location number.
How can i make it to take the -90 and print it out ?


As mentioned on your other (somewhat duplicate) topic...

http://www.coderanch.com/t/481595/Java-General/java/using-indexOf-just-take-RSSI

There are other methods of the java.lang.String class, that can help you here.

Henry
 
fred rosenberger
lowercase baba
Bartender
Posts: 12147
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
The best way to figure out how to code it is to write out how you would do it by hand.

Say you were going to hand a piece of paper to someone with this data on it. They don't know what ANY of this stuff means, what's relevant and what's not.

How would you tell them to find the specific piece of data you want from each line?
 
    Bookmark Topic Watch Topic
  • New Topic