log.h 1.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// log.h

#ifndef _LOG_H
#define _LOG_H

// The logging framework. Use logInit() during initialization to set
// up logging. Then use log() to generate messages. logCleanup()
// should be called during program shutdown.

// logInit() opens a file, sets what types of logging messages to
// actually print, and determines whether timestamps should be
// prepended onto messages. Logging is disabled if 'filename' is NULL
// or 'flags' is 0.
//
// 'filename' is the name of the file to be used for logging. It is
// opened in append mode.
//
// 'flags' is the logical or of one or more of the LOG_TYPEs defined
// below or 0. This determines which of the message types to print out.
//
// If 'useTimestamp' is 1, then timestamps are prepended to each
// message, otherwise, they are ignored.
void logInit(FILE * destFile, int flags, int useTimestamp);

// logCleanup() cleans up the logging state.
void logCleanup(void);

// The logWrite() function is used to print a logging message.
//
// 'flags' is the logical or of one or more of the LOG_TYPEs defined
// below. This tags the logging message so it can be selectively
// filtered. This should never be '0'. If it is '0', the message will
// not be printed.
// 'format' printf-style formatting string. It and any extra variables
// act just like a normal printf call. This is where you actually
// write your message. It will be written to the logging file.
void logWrite(int flags, char const * format, ...);

enum LOG_TYPE
{
41
42
43
44
45
46
47
48
49
50
51
52
53
  ERROR            = 0x0001,
  EXCEPTION        = 0x0002,
  PEER_CYCLE       = 0x0004,
  SENSOR           = 0x0008,
  CONNECTION_MODEL = 0x0010,
  ROBUST           = 0x0020,
  MAIN_LOOP        = 0x0040,
  COMMAND_INPUT    = 0x0080,
  CONNECTION       = 0x0100,
  PCAP             = 0x0200,
  COMMAND_OUTPUT   = 0x0400,
  SENSOR_DETAIL    = 0x0800,
  SENSOR_COMPLETE  = 0x1000,
54
  // Shortcuts for common cases.
55
56
  LOG_NOTHING      = 0x0000,
  LOG_EVERYTHING   = 0x1fff
57
58
59
};

#endif