Forums Register Login

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

+Pie Number of slices to send: Send
Does anyone know how to read a log file in .log and output the data using java language ?
Please help me !!!
+Pie Number of slices to send: Send
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?

+Pie Number of slices to send: Send
".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?
+Pie Number of slices to send: Send
 

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 ?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
Is there any reason to display it with Java? Can't you just use the command line or an editor?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.

+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
Check out String.split, but take into account that | means something special when used as an argument to String.split.
+Pie Number of slices to send: Send
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...
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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 .
+Pie Number of slices to send: Send
 

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 ?
+Pie Number of slices to send: Send
 

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...

https://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
+Pie Number of slices to send: Send
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?
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


Reply locked
This thread has been viewed 5564 times.
Similar Threads
How to redirect Tomcat's console output into a log file?
Does anyone know how to write contour using java language ?
Javamail MimeMessage.writeTo(..)
Monitoring File System
MSSQL and Unicode in WIndows and Linux
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:44:13.