Man pages for syslog(3), syslog.conf(5), syslogd(8)
Why should servers log?
Depends on the service.
Normally a log entry contains several pieces of information:
Basic choices:
Creating a log entry: (Simple version)
Problems with this?
Some solutions to these problems:
Unix provides a flexible logging facility:
syslog
The following calls are used:
syslog uses a Unix domain socket to talk to the logging daemon: syslogd
It solves both the concurrency and performance problems.
Priorities are encoded as a facility and a level.
Levels are:
Log options:
Typical usage:
openlog("myservice", LOG_PID, LOG_DAEMON);
syslog(LOG_ERR, "Sorry, error #%d", errno);
Generated by syslogd:
Mar 12 08:20:06 sciences pppd[28492]: ioctl(SIOCSIFASYNCMAP): No such device or address
Generated by httpd:
rohan.sdsu.edu - - [17/Feb/1995:00:04:47 -0800] "GET / HTTP/1.0" 200 4945
Two basic types:
Plain text is preferable, but there are cases where record based logs are desirable:
To analyze these logs, you need tools.
Examples:
When logs are used as a justification tool, reports need to be generated.
SDSUanalyze:
Generate a graph of average usage per time interval:
Report of usage for the last 5 days in intervals of 60 minutes
Time Logins Relative logins
00:00 (150) *******
01:00 (146) *******
02:00 (147) *******
03:00 (137) *******
04:00 (132) ******
05:00 (122) ******
06:00 (156) ********
07:00 (210) ***********
08:00 (445) ***********************
09:00 (562) *****************************
10:00 (688) ************************************
11:00 (769) ****************************************
12:00 (794) *****************************************
13:00 (1139) ************************************************************
14:00 (994) ****************************************************
15:00 (744) ***************************************
16:00 (475) *************************
17:00 (257) *************
18:00 (210) ***********
19:00 (177) *********
20:00 (166) ********
21:00 (164) ********
22:00 (155) ********
23:00 (148) *******
9034 succesful logins, 53 unsuccesful logins
A tool to build projects.
Typical Makefile:
#
# Makefile for project X
# 4/1/1942
#
CFLAGS= -g -I/usr/local/include
LIBS= -lresolv
CC= gcc
OBJS= file1.o file2.o
TARGET= X
$(TARGET): $(OBJS)
$(CC) -o $@ $(OBJS)
Large projects have:
Each directory needs to have its own Makefile, even documentation directories.
Each Makefile needs a standard set of targets to include:
Each Makefile can include a configuration file:
#
# Makefile for program Y in project X
# 4/1/42
#
include ../Makefile.config
TARGET= Y
OBJS= Y1.o Y2.o
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) -o $@ $(OBJS)
#
# Makefile.config for project X
# 4/1/42
#
CC= gcc
CFLAGS= -g
In the project's main Makefile, you can use something like the following:
#
# Main Makefile for project X
# 4/1/42
#
DIRS= src lib doc db
all:
@for dir in $(DIRS); \
(cd $$dir; $(MAKE) $(MFLAGS) all); \
done;
install:
@for dir in $(DIRS); \
(cd $$dir; $(MAKE) $(MFLAGS) install); \
done;
etc...