CS 596: Client-Server Programming
| Logging | slide # 1 |
| ...What should be logged? | slide # 2 |
| ...How should clients and servers log? | slide # 3 |
| ......Appending to a log file | slide # 4 |
| ......Simple appending problems | slide # 5 |
| ...Use a system logging facility | slide # 6 |
| ......Syslog priorities | slide # 7 |
| ......Syslog sample log entries | slide # 8 |
| ...Types of logs | slide # 9 |
| ......Log file analysis | slide # 10 |
| ...Java log file I/O | slide # 11 |
| Runtime configuration files | slide # 12 |
| ...Location of program parameters | slide # 13 |
| ...Configuration file formats | slide # 14 |
| ...Two basic types of config files | slide # 15 |
| ...Problems with some configuration files | slide # 16 |
Doc 25, Logging and Configuration Files, Slide #1
Why logging?
Who does logging?
Doc 25, Logging and Configuration Files, Slide #2
Normally a log entry contains several pieces of information:
Doc 25, Logging and Configuration Files, Slide #3
Basic choices:
Doc 25, Logging and Configuration Files, Slide #4
Creating a log entry: (Simple version)
Doc 25, Logging and Configuration Files, Slide #5
This simplistic approach can cause problems with the following:
Some solutions:
Doc 25, Logging and Configuration Files, Slide #6
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:
Doc 25, Logging and Configuration Files, Slide #7
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
Doc 25, Logging and Configuration Files, Slide #8
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.
Doc 25, Logging and Configuration Files, Slide #9
Two basic log file types:
Plain text is preferable, but there are cases where record based logs are desirable:
Disadvantages of binary log files:
Doc 25, Logging and Configuration Files, Slide #10
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
Doc 25, Logging and Configuration Files, Slide #11
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);
}
}
}
Doc 25, Logging and Configuration Files, Slide #12
What is a configuration file?
Who needs a configuration file?
Kinds of information found in configuration files:
Doc 25, Logging and Configuration Files, Slide #13
Assignment of configuration parameters can be specied in different ways:
Issues to decide what to use:
Doc 25, Logging and Configuration Files, Slide #14
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:
Doc 25, Logging and Configuration Files, Slide #15
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
Doc 25, Logging and Configuration Files, Slide #16
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: