TcpLogger.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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_TCPLOGGER_H
10 #define _SQUID_SRC_LOG_TCPLOGGER_H
11 
12 #include "base/AsyncJob.h"
13 #include "ip/Address.h"
14 
15 #include <list>
16 
17 class MemBlob;
19 
20 namespace Log
21 {
22 
27 class TcpLogger : public AsyncJob
28 {
30 
31 public:
33 
34  /* Logfile API */
35  static int Open(Logfile *lf, const char *path, size_t bufSz, int fatalFlag);
36 
37 protected:
38  TcpLogger(size_t, bool, Ip::Address);
39  virtual ~TcpLogger();
40 
45  void endGracefully();
46 
48  void logRecord(const char *buf, size_t len);
49 
51  void flush();
52 
53  /* AsyncJob API */
54  virtual void start();
55  virtual bool doneAll() const;
56  virtual void swanSong();
57 
58 private:
59  /* Logfile API. Map c-style Logfile calls to TcpLogger method calls. */
60  static void Flush(Logfile *lf);
61  static void WriteLine(Logfile *lf, const char *buf, size_t len);
62  static void StartLine(Logfile *lf);
63  static void EndLine(Logfile *lf);
64  static void Rotate(Logfile *lf, const int16_t);
65  static void Close(Logfile *lf);
66 
67  static TcpLogger *StillLogging(Logfile *lf);
68 
69  static void DelayedReconnect(void *data);
70  void delayedReconnect();
71 
72  bool canFit(const size_t len) const;
73  void appendRecord(const char *buf, size_t len);
74  void appendChunk(const char *chunk, const size_t len);
75  void writeIfNeeded();
76  void writeIfPossible();
77  void doConnect();
78  void disconnect();
79 
80  /* comm callbacks */
82  void writeDone(const CommIoCbParams &io);
83  void handleClosure(const CommCloseCbParams &io);
84 
85  static const size_t IoBufSize;
86  static const size_t BufferCapacityMin;
87 
91  bool dieOnError;
92 
93  std::list<MemBlobPointer> buffers;
94  size_t bufferCapacity;
95  size_t bufferedSize;
96  size_t flushDebt;
97 
98  bool quitOnEmpty;
101 
105 
106  uint64_t connectFailures;
107  uint64_t drops;
108 };
109 
110 } // namespace Log
111 
112 #endif /* _SQUID_SRC_LOG_TCPLOGGER_H */
113 
void connectDone(const CommConnectCbParams &conn)
Comm::ConnOpener callback.
Definition: TcpLogger.cc:264
static const size_t IoBufSize
fixed I/O buffer size
Definition: TcpLogger.h:85
static void Rotate(Logfile *lf, const int16_t)
Definition: TcpLogger.cc:426
static TcpLogger * StillLogging(Logfile *lf)
Definition: TcpLogger.cc:392
Definition: File.h:38
virtual bool doneAll() const
whether positive goal has been reached
Definition: TcpLogger.cc:74
size_t bufferCapacity
bufferedSize limit
Definition: TcpLogger.h:94
size_t bufferedSize
number of log record bytes stored in RAM now
Definition: TcpLogger.h:95
size_t flushDebt
how many record bytes we still need to write ASAP
Definition: TcpLogger.h:96
hbase_f Log
Definition: StatHist.cc:21
bool reconnectScheduled
we are sleeping before the next connection attempt
Definition: TcpLogger.h:99
uint64_t connectFailures
number of sequential connection failures
Definition: TcpLogger.h:106
void writeDone(const CommIoCbParams &io)
Comm::Write callback.
Definition: TcpLogger.cc:330
TcpLogger(size_t, bool, Ip::Address)
Definition: TcpLogger.cc:37
void const char HLPCB void * data
Definition: stub_helper.cc:16
static void StartLine(Logfile *lf)
Definition: TcpLogger.cc:414
static int Open(Logfile *lf, const char *path, size_t bufSz, int fatalFlag)
Definition: TcpLogger.cc:448
RefCount< MemBlob > MemBlobPointer
Definition: TcpLogger.h:17
void writeIfPossible()
starts writing if possible
Definition: TcpLogger.cc:136
void writeIfNeeded()
starts writing if and only if it is time to write accumulated records
Definition: TcpLogger.cc:127
CBDATA_CLASS(TcpLogger)
bool dieOnError
Definition: TcpLogger.h:91
virtual void swanSong()
Definition: TcpLogger.cc:96
std::list< MemBlobPointer > buffers
I/O buffers.
Definition: TcpLogger.h:93
void doConnect()
starts [re]connecting to the remote logger
Definition: TcpLogger.cc:243
void delayedReconnect()
"sleep a little before trying to connect again" event callback
Definition: TcpLogger.cc:320
static void WriteLine(Logfile *lf, const char *buf, size_t len)
Definition: TcpLogger.cc:407
void logRecord(const char *buf, size_t len)
buffers record and possibly writes it to the remote logger
Definition: TcpLogger.cc:119
bool writeScheduled
we are waiting for the latest write() results
Definition: TcpLogger.h:100
static const size_t BufferCapacityMin
minimum bufferCapacity value
Definition: TcpLogger.h:86
void appendRecord(const char *buf, size_t len)
buffer a record that might exceed IoBufSize
Definition: TcpLogger.cc:202
CbcPointer< TcpLogger > Pointer
Definition: TcpLogger.h:32
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
void const char * buf
Definition: stub_helper.cc:16
bool quitOnEmpty
whether this job should quit when buffers are empty
Definition: TcpLogger.h:98
virtual void start()
called by AsyncStart; do not call directly
Definition: TcpLogger.cc:68
void appendChunk(const char *chunk, const size_t len)
buffer a record chunk without splitting it across buffers
Definition: TcpLogger.cc:222
AsyncCall::Pointer closer
handles unexpected/external conn closures
Definition: TcpLogger.h:104
void disconnect()
close our connection now, without flushing
Definition: TcpLogger.cc:377
void handleClosure(const CommCloseCbParams &io)
Definition: TcpLogger.cc:366
Comm::ConnectionPointer conn
opened connection to the remote logger
Definition: TcpLogger.h:102
static void DelayedReconnect(void *data)
Log::TcpLogger::delayedReconnect() wrapper.
Definition: TcpLogger.cc:303
uint64_t drops
number of records dropped during the current outage
Definition: TcpLogger.h:107
bool canFit(const size_t len) const
whether len more bytes can be buffered
Definition: TcpLogger.cc:159
static void Close(Logfile *lf)
Definition: TcpLogger.cc:431
virtual ~TcpLogger()
Definition: TcpLogger.cc:61
static void Flush(Logfile *lf)
Definition: TcpLogger.cc:400
Ip::Address remote
where the remote logger expects our records
Definition: TcpLogger.h:103
void endGracefully()
Definition: TcpLogger.cc:103
static void EndLine(Logfile *lf)
Definition: TcpLogger.cc:419
void flush()
write all currently buffered records ASAP
Definition: TcpLogger.cc:112

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors