[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

record user log

Posted on 2007-08-07
34
Medium Priority
?
287 Views
Last Modified: 2013-11-05
Hello there,

I have a application which is logging user action.when they close the application properly i log their logout time.but i want to also log the logout time even if they just swtich off the computer directly or for some reason the computer just closes the application.how do i log this type of event.please help.

cheers
zolf
0
Comment
Question by:zolf
  • 13
  • 12
  • 5
  • +1
34 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 600 total points
ID: 19644347
You can catch events with a ShutdownHook. See Runtime class
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19644362
http://www.esus.com/javaindex/j2se/jdk1.2/javalang/trapctrlc.html

There are times when that won't work unfortunately
0
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 600 total points
ID: 19644364
I think the ShutdownHook won't work if the computer is just switched off or hanged.

I think, user session timeout may better approach, i.e., trigger logout from server itself over a period of idle...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:zolf
ID: 19644378

thanks everybody for your comment

ksivananth:
can you give me an example.

my application is java swing jnlp application.i dont think i can have session in these type of application.
0
 
LVL 16

Accepted Solution

by:
ellandrd earned 800 total points
ID: 19644388
I have never heard of such a class or library, but maybe their is a class that can detect when application unexpectedly closes or crashes and log the time when it does??

I also found this:

http://forum.java.sun.com/thread.jspa?threadID=554514&messageID=2715820

ellandrd
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19644391
You'll probably get better control with a backing service. A Windows service if you're not interested in x-platform
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 19644394
>>my application is java swing jnlp application.i dont think i can have session in these type of application.

yes, then you can't!

Probably, for worst cases, you may have some background thread which keep updating the current time in a properties file or persisting in some means! So atleast you know that the time when the app/system wentdown without proper logout!
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 19644406
since it is a jnlp applcaition, couldnt you write to the log file when it goes offline?

http://lopica.sourceforge.net/faq.html#offline

ellandrd
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19644422
Java is not really suitable if you need that sort of control
0
 

Author Comment

by:zolf
ID: 19644430

ellandrd:
cool i think that should help.do i insert that piece of code into my main class.please help.

cheers
zolf
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 19644439
>>Java is not really suitable if you need that sort of control

I am wondering if there are any other lang where you can do this!
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 19644448
>>cool i think that should help.do i insert that piece of code into my main class.please help.

I don't understand how that helps here?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19644449
>>I am wondering if there are any other lang where you can do this!

You need to run that as a service, or backed by a service
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 19644460
>>You need to run that as a service, or backed by a service

if the system is turned off or power failure, can a service respond?
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 19644461
>>I don't understand how that helps here?

OK this is what i was thinking... if the user powers the machine off or closes the JNLP application incorrectly, then the host will be lost - right?  So if the host is close - you can detect this unexpected event...

ellandrd
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 19644471
>>So if the host is close - you can detect this unexpected event...

how?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19644483
You can't detect kernel level events at the application level. You can only integrate as far as possible with the kernel - i.e. running a service
0
 

Author Comment

by:zolf
ID: 19644487


please help me.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19644491
>>You can't detect kernel level events at the application level.

.. or at least not practicably
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 19644492
>>how?

see above
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19644496
>>please help me

I just have done ...
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 19644498
The workaround is just to detect if your application is running offline or online... I don't see that will help here!
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 19644515
>>You can't detect kernel level events at the application level. You can only integrate as far as possible with the kernel - i.e. running a service
>>

I don't think app/service can recieve any events in case of power failure or turn off!
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 19644522
I think, one possible way is "you may have some background thread which keep updating the current time in a properties file or persisting to disk in some means! So atleast you know that the time when the app/system wentdown without proper logout!"
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19644528
"you may have some background thread ..."

What - like a service you mean?
0
 

Author Comment

by:zolf
ID: 19644529

so i cannot log those type of events.
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 19644530
>>The workaround is just to detect if your application is running offline or online... I don't see that will help here!

I agree - my suggestion isnt a complete solution - from what has been said so far in this discussion, i dont think their is a complete solution...

ellandrd
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 19644536
>>What - like a service you mean?

no, background thread in application
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 19644543
>>I agree - my suggestion isnt a complete solution

IMHO, the suggestion will not help at all!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19644564
>>no, background thread in application

A service thread will be more robust.

I'm interested to know why you accepted that particular answer zolf
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 19644576
>>A service thread will be more robust.

I don't for this operation, we don't need a service thread!

>>I'm interested to know why you accepted that particular answer zolf

Me too...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19644654
>>I don't for this operation, we don't need a service thread!

For just one example, a service thread will survive a logout. A ShutdownHook is not always called on logout. An ordinary thread that simply stops logging because it's had the rug pulled from under it is a kludge, relatively speaking
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 19644675
>>For just one example, a service thread will survive a logout.

May be if the system is logging out what if it is turned off or power failure?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19644688
Well obviously there are more or less fatal circumstances that can occur. The point is to approach it from the most solid base possible, and that base is integration with the kernel
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question