Logging can be very helpful in analyzing the (faulty) behavior of a server application in response to client requests. HypertextLogger is a simple component that produces HTML in response to logging instructions. Its main purpose it to provide a better readable log file. By choosing you favorite CSS, you can highlight what is important and leave other information unfocused (timestamps).
- missing image /2009/06/hypertextlogger.png
Upon creation of the logger, it produces a new .html file to which logging events are written. Because most Browsers can deal with open-ended (i.e. not properly closed by tags) HTML files, a single page can be used to collect lots of events. And if you let e.g. Apache serve these log files, you can monitor server applications remotely.
Features of the HypertextLogger are:
- the log can be custom CSS styled (info,warn and error levels may have different emphasis)
- the log can have a custom pattern for each event (write your own formatBlock)
- you can use any HTML markup (e.q. links to other resources)
- by choosing a FileRollingPolicy you can control how many events are logged onto a single HTML file
- [update] can capture Transcript output and include it in the log
Using the logger
| logger | logger := HypertextLogging.HypertextLogger onFileNamed: 'myproject.log'. logger debug: 'This is debugging info only shown if level == #debug'. logger link: 'http://blog.doit.st' title: 'Smalltalk in the Cloud'.
Logger APISome examples using the logging api. See class methods for tests.
logger blue: 'Text in Blue'. logger escaped: '<escaped>'. logger red:[ logger strong: 'Bummer' ]. "use blocks to combine the api" logger logException: aSignal. "writes a stack" logger enabled: true. logger printTimestamp. logger printCurrentProcess.
Customizing the loggerYou can override the CSS styles and the format of each log entry.
logger css: aDictionary. "mapping between css-class and its definition" logger formatBlock: [:logger :logLevel :content | logger print: content ]. "provide your own entry formatting"
Setup the FileRollingPolicyInstead of producing one single big file, you can specify a policy to control log file creation.
logger daily. "every day create a new log (unless no events)" logger maximumSize: 100000. "if size reaches limit then create a new log" logger maximumEntries: 1000. "limit on the number of events" logger refreshEvery: 10. "10 seconds auto refresh by the browser"
HypertextLogger is implemented in VisualWorks Smalltalk and is available from the Cincom Public Store under MIT License.
Update: 1.8.4: if rolling policy is set then do not overwite exising log when new logger is created.
Logging can be very helpful in analyzing the (faulty) behavior of a server application in response to client requests. HypertextLogger is a simple component that produces HTML in response to logging instructions.comments powered by Disqus