Why logging?
Who does logging?
Normally a log entry contains several pieces of information:
Basic choices:
Creating a log entry: (Simple version)
This simplistic approach can cause problems with the following:
Some solutions:
Unix provides a flexible client-server based logging facility:
syslog
Unfortunately, syslog cannot be directly accessed from within a java
program.
Also, the system administrator has to configure syslog, although any user can
log to it.
Advantages of a system logging facility like syslog:
Priorities are encoded as facility and level.
Levels:
LOG_EMERG Panic conditions LOG_ALERT Urgent things LOG_CRIT Critical stuff LOG_ERR Errors LOG_WARNING Warnings LOG_NOTICE Non-errors LOG_INFO Information LOG_DEBUG Debugging
Facilities:
LOG_KERN Kernel messages LOG_USER Random user processes LOG_MAIL The mail system LOG_DAEMON System daemons LOG_AUTH Login, su, getty LOG_LPR Printing system LOG_NEWS USENET news LOG_UUCP Never used LOG_CRON Cron system LOG_LOCAL0-7 Reserved for local use
Log entry generated by sendmail through syslog:
Apr 13 07:55:53 ender sendmail[20367]: HAA20367: from=<xforms@ra.york.cuny.edu>, size=1528, class=-60, pri=0, nrcpts=1, msgid=<9604131433.AA16720@szechuan.UCSD.EDU>, proto=ESMTP, relay=sdsu.edu [130.191.229.14]
Log entry generated by the printing system through syslog:
Apr 16 03:05:40 spaceballs.sdsu.edu printer: paper out
The
format used depends on what the logs are going to be used for.
Note the use of name-value pairs in the sendmail log entry.
Two
basic log file types:
Plain text is preferable, but there are cases where record based logs are
desirable:
Disadvantages of binary log files:
Raw log files are normally not very useful.
Log analysis tools can show information that cannot easily been seen by looking
at the raw logs.
Example: SDSUanalyze
Report of usage for the last 5 days in intervals of 60 minutes Time Logins Relative logins 00:00 (123) ********* 01:00 (121) ********* 02:00 (121) ********* 03:00 (122) ********* 04:00 (122) ********* 05:00 (143) *********** 06:00 (180) ************** 07:00 (252) ******************* 08:00 (491) ************************************** 09:00 (678) ***************************************************** 10:00 (678) ***************************************************** 11:00 (731) ********************************************************* 12:00 (767) ************************************************************ 13:00 (754) ********************************************************** 14:00 (655) *************************************************** 15:00 (592) ********************************************** 16:00 (391) ****************************** 17:00 (244) ******************* 18:00 (220) ***************** 19:00 (178) ************* 20:00 (176) ************* 21:00 (176) ************* 22:00 (168) ************* 23:00 (126) ********* 8178 succesful logins, 31 unsuccesful logins
Java doesn't have an explicit "append" file IO system.
Use the RandomAccessFile class.
For example:
import java.io.RandomAccessFile; class AppendSomething { public static void main(String args[]) { RandomAccessFile file; try { file = new RandomAccessFile("foo", "rw"); file.seek(file.length()); file.write("Appended " + args[0] + "\n"); } catch (Exception e) { System.err.println(e); } } }
What is a configuration file?
Who needs a configuration file?
Kinds of information found in configuration files:
Assignment of configuration parameters can be specied in different ways:
Issues to decide what to use:
Runtime configuration files need to be interpreted by a program.
Issues with the format:
Best of both worlds: A configuration file which is human readable but also
easy to read/modify by a program.
Many of the same rules that we have seen for protocol design apply to
configuration files:
There seem to be two main ideas with configuration files:
Some examples of "Good"
configuration file formats
Microsoft .INI files:
[GROUP Identifier] name1=value1 name2=value2 etc.
X11 defaults files:
class.application.name: value1 *.name: value2
Fvwm configuration file:
AddToMenu "Utilities" "Utilities" Title + "Recapture" Recapture + "Paging" TogglePage + "Refresh" Refresh + "Windows" WindowList
Configuration programs need to be complete.
They should be able to do ALL possible things that the configuration file
allows.
Some examples where this is not true: