Apcupsd システムロギング

訳者:Que 21 Mar 2000 (http://homepage1.nifty.com/Que/)


apcupsd の哲学は,全てのロギングが syslog 機構を通してされるべきであるということです(man syslog 参照)。これは現在,STATUS ロギングがまだファイルにされる - 先のバージョンとの互換性のために - 例外とともにインプリメントされています。そして、EVENTSロギングは Temporary ファイルに向けられることができます ― それがネットワーク情報サーバーによって報告されることができるように。

Apcupsd は,

1. DEBUG
2. DATA
3. STATUS
4. EVENTS
と呼ばれる,4つの独立したタイプにロギングします。

DEBUG ログ

デバッグ・ログは、デバッグメッセージから成ります。通常は、これらは開発者によってのみオンにされます。そして、現在、これらデバッグ・メッセージはごく少数しか存在しません。

DATA ログ

データロギングは、UPSの動作に関して定期的にログしている重要なデータから成ります。詳細は、このマニュアルのDATA Formatセクションをご覧下さい。

STATUS ログ

ステータスロギングは、ASCIIレコードの列として得られる 知りうるすべての UPS についての情報から成ります。この情報はまた、apcupsdネットワークインフォメーションサーバによっても.

ステータスロギングについての詳細は、このマニュアルのSTATUS Formatセクションをご覧下さい。

EVENTS Logging

Events logging consists of logging events as they happen. For example, successful startup, power fail, battery failure, system shutdown, ...

See the EVENTS Format section of this manual for more details.

Implementation Details

In order to ensure that the data logged to syslog() can be directed to different files, I have assigned syslog() levels to each of our four types of data as follows:

1. DEBUG logging has level LOG_DEBUG 3. STATUS logging has level LOG_NOTICE
4. EVENTS logging has levels LOG_WARNING, LOG_ERR, LOG_CRIT, and LOG_ALERT

It should be noted that more work needs to be done on the precise definitions of each of the levels for EVENTS logging. Currently, it is roughly broken down as follows:

LOG_WARNING general information such as startup, etc.
LOG_ERR an error condition detected, e.g. communications problem with the UPS.
LOG_CRIT a serious problem has occurred such as power failure, running on UPS batteries, ...
LOG_ALERT a condition that needs immediate attention such as pending system shutdown, ...

More work needs to be done to the code to ensure that it corresponds to the above levels.

As a practical example of how to setup your syslog() to use the new logging feature, suppose you wish to direct all DATA logging to a file named /var/log/apcupsd.data, all EVENTS to the standard /var/log/messages file (to be mixed with other system messages), and at the same time send all EVENTS to /var/log/apcupsd.events, and finally, you want to send all STATUS logging to the named pipe /var/log/apcupsd.status

First as root, you create the named pipe:

mkfifo /var/log/apcupsd.status

change its permissions as necessary or use the -m option to set them when creating the pipe.

Then you modify your /etc/syslog.conf file to direct the appropriate levels of messages where you want them. To accomplish the above, my syslog.conf file looks like:

# exclude all apcupsd info by default
*.info;local0.none                    /var/log/messages

# Everything for apcupsd goes here
local0.info;local0.!notice             /var/log/apcupsd.data
local0.notice;local0.!warn            |/var/log/apcupsd.status
local0.warn                            /var/log/apcupsd.events
local0.warn                            /var/log/messages

Developer's Notes

All logging functions and all error reporting are now done through the log_event() subroutine call. Exceptions to this are: initialization code where printf's are done, and writing to the status file. Once the initialization code has completed and the fork() to become a daemon is done, no printf's are used. log_event() has exactly the same format as syslog(). In fact, the subroutine consists of only a syslog() call. If anyone really wishes to log to a file, the code to do so can easily be done by adding code to log_event() in apclog.c.