Projects
JavaScript Server-Side Console
This script partially implements the Firebug Console API for server-side JavaScript using the Wildfire/FirePHP protocol. It currently runs on Aptana Jaxer and “Classic” ASP, and AppJet, though support for other server-side JavaScript platforms is planned for future releases.
Requirements
Server
- Jaxer 1.0 or newer
or
- Microsoft IIS
- Prototype ASP (for JSON support.)
or
- AppJet
Client
- Mozilla Firefox
- The Firebug extension
- The FirePHP extension
Differences Between Firebug/FirePHP and This
The Firebug Console API lets you log multiple objects in one statement and use them with the string substition (i.e. console.log("My object: %o", obj)). This implementation only lets you log a single object at a time. If the first argument to one of the functions is an object (that is, anything that responds with "object" to the typeof operator) it will be shown using FirePHP's Variable Viewer. If the list of arguments starts with a string or number, it will be logged as a text message.
These methods of the Firebug Console API are not currently implemented:
- console.assert()
- console.count()
- console.dir()
- console.dirxml()
- console.profile()
- console.profileEnd()
- console.trace()
These features of FirePHP are not implemented:
- Dump
- Table
- Trace
Some of these will be implemented in future releases, others will not.
In addition, you can enable and disable messages from appearing with console.enable() and console.disable() respectively.
Usage
- Download console.js and put it where your web files are stored.
- Include it in a page:
On ASP:
<script src="prototype.js" language="JavaScript" runat="server"></script>
<script src="console.js" language="JavaScript" runat="server"></script>
<script language="JavaScript" runat="server">
console.log("Hello world!");
console.info("And", "so", "on");
</script>
On Appjet:
The console library is hosted at http://lib-console.appjet.net/. You can use it in your own AppJet applications by calling import('lib-console');.
An example page is hosted at http://console-test.appjet.net/.
On Jaxer:
<script src="console.js" runat="server"></script>
<script runat="server">
console.log("Hello world!");
console.info("And", "so", "on");
</script>
As a Jaxer Extension:
Download the Jaxer extension and place it into your local_jaxer/extensions directory. Once Jaxer is restarted, the Jaxer.console object becomes available to all scripts. Usage is the same as above, except the script does not need to be included and Jaxer.console is used instead of console.
Echoing to the Jaxer log can be enabled and disabled by setting Jaxer.console.echo to true and false respectively.
These Boolean options can also be set in your local_jaxer/conf/config.js:
CONSOLE_DISABLEDCONSOLE_ECHO_TO_LOG
History
Version 0.0.4
November 21, 2008
- Added AppJet support
Version 0.0.3
November 20, 2008
- Added Jaxer extension
Version 0.0.2
November 12, 2008
- Added ASP support
- Added MIT License and change log
- Fixed Jaxer toJSON bug
- Minor code cleanup
Version 0.0.1
November 9, 2008
- Initial release
Known Issues
- If too many messages are logged in a given request, the server will not respond at all. What “too many” is depends on your platform. If your server does not respond, don't log so many messages or disable the console object. This threshold is reasonably high on ASP, and there is a bug report open for Jaxer.
- If you find any other problems or have any comments, please contact me.
Acknowledgements
This script would not have been possible without the help of these people:
- Christoph Dorn, for the FirePHP library
- Joe Hewitt, et. al. (did people make websites before Firebug?)
- The folks at webtoolkit.info, for their
sprintfimplementation - Davey at Aptana, and the whole Aptana staff for all of their help with Jaxer and the T-shirt