PDA

View Full Version : Showing server logs with "tail"



adrian.tarau
25 Nov 2007, 2:02 PM
Hello,

I'm trying to show server logs in a similar way as "tail" on *NIX systems. I started to extend an Ext.Panel and using a timer I'm requesting new sections of the log - json response.

The problem is I don't know how to insert the response(a bunch of div's) in the panel body and to have a scrollbar.

Thanks.



/**
* @class Ext.LogViewer
* @extends Ext.Panel
* This class loads a file from the server in a UNIX tail fashion
* @constructor
* Create a new LogViewer
* @param {Object} config The configuration options
*/
Ext.LogViewer = Ext.extend(Ext.Panel, {
/**
* @cfg {Number} refresh number of seconds to refresh (defaults to 5).
*/
refresh : 5,
/**
* @cfg {Number} position log postion .
*/
position : 0,

/**
* @cfg {Number} logId log identifier.
*/
logId : '',

/**
* @cfg {String} magicNumber log session identifier.
*/
magicNumber : '',

/**
* @cfg {String} url log handler url.
*/
url : '',

// private
initComponent : function() {
Ext.LogViewer.superclass.initComponent.call(this);

Ext.TaskMgr.start({
run : this.load,
interval : this.refresh * 1000 || 5000,
scope: this
});
},

load : function() {
var transId = Ext.Ajax.request({
method:"GET",
url: this.url,
success: this.handleResponse,
failure: this.handleFailure,
scope: this,
params: {id : this.logId, position : this.position, magicNumber : this.magicNumber}
});
return transId;
},

clear : function() {
},

handleResponse : function(response) {
var json = response.responseText;
var enties = eval("(" + json + ")");
this.position = enties.position;
/*if (this.magicNumber != enties.magicNumber) {
clear();
} */
this.magicNumber = enties.magicNumber;
if (enties.text && enties.text.length > 0) {
this.getEl().insertHtml("afterBegin", enties.text, false); ?????? At this point the text appears somewhere in the panel but I have no scroll bar.
}
},

handleFailure : function(response) {
}

});

hendricd
25 Nov 2007, 2:49 PM
If you defaulted a bodyStyle for your class, you could maintain header, footer, toolbars around the log body and use:




Ext.LogViewer = Ext.extend(Ext.Panel, {
/**
* @cfg {Number} refresh number of seconds to refresh (defaults to 5).
*/
refresh : 5,

/**
* @cfg {Number} bodyStyle default styling for log body.
*/
bodyStyle:{ overflow:'auto' , others:....... },


and...

handleResponse : function(response) {
var json = response.responseText;
var enties = eval("(" + json + ")");
this.position = enties.position;
/*if (this.magicNumber != enties.magicNumber) {
clear();
} */
this.magicNumber = enties.magicNumber;
if (enties.text && enties.text.length > 0) {
this.body.insertHtml("afterBegin", enties.text, false);
}
},

adrian.tarau
26 Nov 2007, 7:46 PM
Works like a charm :) Thanks.

tdema
3 Apr 2008, 6:58 PM
Hey adrian.tarau,

This is what I am trying to do.. Tail my server log files for our tech support department. Would you be willing to share your HTML and server script so I can see how you pulled this all together? Of course, where security isn't compromised. Thanks.

tonyd

adrian.tarau
4 Apr 2008, 10:33 AM
Sorry I didn't saw your post, do you still need this?

ilazarte
4 Apr 2008, 11:25 AM
post it for the curious!

tdema
4 Apr 2008, 12:21 PM
I sure do!! I'm having trouble getting my tail from my server script to update my container. All I get is one line response. To get all of the data, I have to build a large string on the server side and send it in one response. So it's not really a tail. So I thought this could shed some light on where I going wrong if I could see both sides client/server. Thanks

tdema

adrian.tarau
4 Apr 2008, 12:52 PM
I'll post the code tonight.

I have an Ext.Panel extension which handles the view and a "handler"(you can use the same code in a servlet) which sends the differences from the last poll. I still have to do some protection, when the log grows faster that the viewer can retrieve(right now I'm only displaying the delay in "remaining" length to be downloaded).

adrian.tarau
5 Apr 2008, 2:53 AM
Here it is.

A few explanations :

There is no hidden magic in any class used by this handler
AbstractWebApplicationURIHandler is similar with a HttpServlet, WebApplicationContext wrapps a HTTP request/response
Some utilities but the function name should tell you what's behind


Any suggestions/fixes are welcomed. The error handler is not implemented, anyway I'm planning to add a global error handler(Ext.jaf.Ajax is just a wrapper on Ext.Ajax which provides some extra support, like global error handling, etc).

I'm doing a huge refactoring now so I'm not able to show you some screen shots. I have a log file for every plug-in/library and I'm using a tree to show the available logs. I hope I will be able to attach some screen shots in 2-3 weeks.

PS. If you need access the source code, post me a private message. The project is free but is not ready yet for prime time :)

tdema
5 Apr 2008, 4:28 PM
Thanks adrian.tarau,

Looking at your java file I see a number of imports. Where are they coming from? And it looks like this is what is running on your server responding to the HttpRequest's. Is that the case? Is is possible to see part or all of your html? I tried to private message you but your profile isn't accepting them at this time. A great deal of thanks.

tonyd

adrian.tarau
5 Apr 2008, 6:35 PM
I went to Options, Enable Private Messaging is enabled, Receive Private Messages only from Buddies and Moderators is enabled. I don't see any other option related to private messages.

As I told you, there is no magic behind those unknown classes. I will try to post you a private message with the SVN url.

Right now the application is broken, I hope I can have the administration console up & running in 1-2 weeks, and you can see it live.

adrian.tarau
5 Apr 2008, 6:52 PM
Sorry, I just realized why you couldn't send me a private message : Receive Private Messages only from Buddies and Moderators :)

Now is disabled...