SDSU CS 596: Client-Server Programming
Spring Semester, 1997
Doc 25, Logging and Configuration Files

To Lecture Notes Index
San Diego State University -- This page last updated Apr 14, 1997
----------

Contents of Doc 25, Logging and Configuration Files

Loggingslide # 1
...What should be logged?slide # 2
...How should clients and servers log?slide # 3
......Appending to a log fileslide # 4
......Simple appending problemsslide # 5
...Use a system logging facilityslide # 6
......Syslog prioritiesslide # 7
......Syslog sample log entriesslide # 8
...Types of logsslide # 9
......Log file analysisslide # 10
...Java log file I/Oslide # 11
Runtime configuration filesslide # 12
...Location of program parametersslide # 13
...Configuration file formatsslide # 14
...Two basic types of config filesslide # 15
...Problems with some configuration filesslide # 16

Doc 25, Logging and Configuration Files, Slide #1

Logging

Why logging?

Who does logging?


Doc 25, Logging and Configuration Files, Slide #2

What should be logged?

Normally a log entry contains several pieces of information:


Doc 25, Logging and Configuration Files, Slide #3

How should clients and servers log?

Basic choices:


Doc 25, Logging and Configuration Files, Slide #4

Appending to a log file

Creating a log entry: (Simple version)

  1. Server opens log file for append
  2. Server writes log entry
  3. Server closes log file

Doc 25, Logging and Configuration Files, Slide #5

Simple appending problems

This simplistic approach can cause problems with the following:

Some solutions:


Doc 25, Logging and Configuration Files, Slide #6

Use a system logging facility

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

Syslog priorities

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

Syslog sample log entries

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

Types of logs

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

Log file analysis

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 log file I/O

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

Runtime configuration files

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

Location of program parameters

Assignment of configuration parameters can be specied in different ways:

Issues to decide what to use:


Doc 25, Logging and Configuration Files, Slide #14

Configuration file formats

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

Two basic types of config 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
	  

Doc 25, Logging and Configuration Files, Slide #16

Problems with some configuration files

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:

----------