1 /*
2  * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_LOG_FILE_H
10 #define SQUID_SRC_LOG_FILE_H
11 
12 #include "cbdata.h"
13 #include "dlink.h"
14 
15 #if HAVE_SYS_PARAM_H
16 #include <sys/param.h>
17 #endif
18 
19 class logfile_buffer_t
20 {
21 public:
22     char *buf;
23     int size;
24     int len;
25     int written_len;
26     dlink_node node;
27 };
28 
29 class Logfile;
30 
31 typedef void LOGLINESTART(Logfile *);
32 typedef void LOGWRITE(Logfile *, const char *, size_t len);
33 typedef void LOGLINEEND(Logfile *);
34 typedef void LOGFLUSH(Logfile *);
35 typedef void LOGROTATE(Logfile *, const int16_t);
36 typedef void LOGCLOSE(Logfile *);
37 
38 class Logfile
39 {
40     CBDATA_CLASS(Logfile);
41 
42 public:
43     explicit Logfile(const char *aPath);
~Logfile()44     ~Logfile() {}
45 
46     char path[MAXPATHLEN];
47 
48     struct {
49         unsigned int fatal;
50     } flags;
51 
52     int64_t sequence_number;  ///< Unique sequence number per log line.
53 
54 public:
55     void *data;
56 
57     LOGLINESTART *f_linestart;
58     LOGWRITE *f_linewrite;
59     LOGLINEEND *f_lineend;
60     LOGFLUSH *f_flush;
61     LOGROTATE *f_rotate;
62     LOGCLOSE *f_close;
63 };
64 
65 /* Legacy API */
66 Logfile *logfileOpen(const char *path, size_t bufsz, int);
67 void logfileClose(Logfile * lf);
68 void logfileRotate(Logfile * lf, int16_t rotateCount);
69 void logfileWrite(Logfile * lf, char *buf, size_t len);
70 void logfileFlush(Logfile * lf);
71 void logfilePrintf(Logfile * lf, const char *fmt,...) PRINTF_FORMAT_ARG2;
72 void logfileLineStart(Logfile * lf);
73 void logfileLineEnd(Logfile * lf);
74 
75 #endif /* SQUID_SRC_LOG_FILE_H */
76 
77