#include <TcpLogger.h>

Inheritance diagram for Log::TcpLogger:
Collaboration diagram for Log::TcpLogger:

Public Types

typedef CbcPointer< TcpLoggerPointer

Public Member Functions

bool canBeCalled (AsyncCall &call) const
 whether we can be called More...
void callStart (AsyncCall &call)
virtual void callEnd ()
 called right after the called job method More...
virtual void callException (const std::exception &e)
 called when the job throws during an async call More...
virtual void * toCbdata ()=0

Static Public Member Functions

static int Open (Logfile *lf, const char *path, size_t bufSz, int fatalFlag)
static Pointer Start (AsyncJob *job)
 starts a freshly created job (i.e., makes the job asynchronous) More...

Protected Member Functions

 TcpLogger (size_t, bool, Ip::Address)
virtual ~TcpLogger ()
void endGracefully ()
void logRecord (const char *buf, size_t len)
 buffers record and possibly writes it to the remote logger More...
void flush ()
 write all currently buffered records ASAP More...
virtual void start ()
 called by AsyncStart; do not call directly More...
virtual bool doneAll () const
 whether positive goal has been reached More...
virtual void swanSong ()
void deleteThis (const char *aReason)
void mustStop (const char *aReason)
bool done () const
 the job is destroyed in callEnd() when done() More...
virtual const char * status () const
 internal cleanup; do not call directly More...

Protected Attributes

const char * stopReason
 reason for forcing done() to be true More...
const char * typeName
 kid (leaf) class name, for debugging More...
AsyncCall::Pointer inCall
 the asynchronous call being handled, if any More...
const InstanceId< AsyncJobid
 job identifier More...

Private Member Functions

void delayedReconnect ()
 "sleep a little before trying to connect again" event callback More...
bool canFit (const size_t len) const
 whether len more bytes can be buffered More...
void appendRecord (const char *buf, size_t len)
 buffer a record that might exceed IoBufSize More...
void appendChunk (const char *chunk, const size_t len)
 buffer a record chunk without splitting it across buffers More...
void writeIfNeeded ()
 starts writing if and only if it is time to write accumulated records More...
void writeIfPossible ()
 starts writing if possible More...
void doConnect ()
 starts [re]connecting to the remote logger More...
void disconnect ()
 close our connection now, without flushing More...
void connectDone (const CommConnectCbParams &conn)
 Comm::ConnOpener callback. More...
void writeDone (const CommIoCbParams &io)
 Comm::Write callback. More...
void handleClosure (const CommCloseCbParams &io)

Static Private Member Functions

static void Flush (Logfile *lf)
static void WriteLine (Logfile *lf, const char *buf, size_t len)
static void StartLine (Logfile *lf)
static void EndLine (Logfile *lf)
static void Rotate (Logfile *lf, const int16_t)
static void Close (Logfile *lf)
static TcpLoggerStillLogging (Logfile *lf)
static void DelayedReconnect (void *data)
 Log::TcpLogger::delayedReconnect() wrapper. More...

Private Attributes

bool dieOnError
std::list< MemBlobPointerbuffers
 I/O buffers. More...
size_t bufferCapacity
 bufferedSize limit More...
size_t bufferedSize
 number of log record bytes stored in RAM now More...
size_t flushDebt
 how many record bytes we still need to write ASAP More...
bool quitOnEmpty
 whether this job should quit when buffers are empty More...
bool reconnectScheduled
 we are sleeping before the next connection attempt More...
bool writeScheduled
 we are waiting for the latest write() results More...
Comm::ConnectionPointer conn
 opened connection to the remote logger More...
Ip::Address remote
 where the remote logger expects our records More...
AsyncCall::Pointer closer
 handles unexpected/external conn closures More...
uint64_t connectFailures
 number of sequential connection failures More...
uint64_t drops
 number of records dropped during the current outage More...

Static Private Attributes

static const size_t IoBufSize = 2*MAX_URL
 fixed I/O buffer size More...
static const size_t BufferCapacityMin = 2*Log::TcpLogger::IoBufSize
 minimum bufferCapacity value More...

Detailed Description

Sends log records to a remote TCP logger at the configured IP:port address. Handles loss of connectivity, record buffering, and buffer overflows.

Definition at line 27 of file TcpLogger.h.

Member Typedef Documentation

◆ Pointer

Definition at line 32 of file TcpLogger.h.

Constructor & Destructor Documentation

◆ TcpLogger()

Log::TcpLogger::TcpLogger ( size_t  bufCap,
bool  dieOnErr,
Ip::Address  them 

Definition at line 37 of file TcpLogger.cc.

References bufferCapacity, BufferCapacityMin, DBG_IMPORTANT, debugs, MY_DEBUG_SECTION, and remote.

Referenced by Open().

◆ ~TcpLogger()

Log::TcpLogger::~TcpLogger ( )

Definition at line 61 of file TcpLogger.cc.

References assert, and writeScheduled.

Member Function Documentation

◆ appendChunk()

void Log::TcpLogger::appendChunk ( const char *  chunk,
const size_t  len 

Definition at line 222 of file TcpLogger.cc.

References bufferedSize, buffers, debugs, IoBufSize, len, Must, MY_DEBUG_SECTION, and writeScheduled.

Referenced by appendRecord().

◆ appendRecord()

void Log::TcpLogger::appendRecord ( const char *  buf,
size_t  len 

Definition at line 202 of file TcpLogger.cc.

References appendChunk(), canFit(), drops, IoBufSize, len, and min().

Referenced by logRecord().

◆ callEnd()

void AsyncJob::callEnd ( )

◆ callException()

◆ callStart()

void AsyncJob::callStart ( AsyncCall call)

◆ canBeCalled()

bool AsyncJob::canBeCalled ( AsyncCall call) const

Definition at line 101 of file AsyncJob.cc.

References AsyncCall::cancel(), debugs, HERE(), AsyncJob::inCall, and NULL.

Referenced by AsyncJob::swanSong().

◆ canFit()

bool Log::TcpLogger::canFit ( const size_t  len) const


Log::TcpLogger::CBDATA_CLASS ( TcpLogger  )

◆ Close()

void Log::TcpLogger::Close ( Logfile lf)

Definition at line 431 of file TcpLogger.cc.

References asyncCall(), Logfile::data, debugs, endGracefully(), NULL, ScheduleCallHere, and StillLogging().

Referenced by Open().

◆ connectDone()

◆ DelayedReconnect()

void Log::TcpLogger::DelayedReconnect ( void *  data)

◆ delayedReconnect()

void Log::TcpLogger::delayedReconnect ( )

Definition at line 320 of file TcpLogger.cc.

References conn, doConnect(), Must, and reconnectScheduled.

Referenced by DelayedReconnect().

◆ deleteThis()

void AsyncJob::deleteThis ( const char *  aReason)

◆ disconnect()

void Log::TcpLogger::disconnect ( )

◆ doConnect()

◆ done()

◆ doneAll()

bool Log::TcpLogger::doneAll ( ) const

Reimplemented from AsyncJob.

Definition at line 74 of file TcpLogger.cc.

References bufferedSize, conn, connectFailures, debugs, AsyncJob::doneAll(), MY_DEBUG_SECTION, and quitOnEmpty.

◆ endGracefully()

void Log::TcpLogger::endGracefully ( )

Called when Squid is reconfiguring (or exiting) to give us a chance to flush remaining buffers and end this job w/o loss of data. No new log records are expected. Must be used as (or inside) an async job call and will result in [eventual] job termination.

Definition at line 103 of file TcpLogger.cc.

References assert, flush(), AsyncJob::inCall, NULL, and quitOnEmpty.

Referenced by Close().

◆ EndLine()

void Log::TcpLogger::EndLine ( Logfile lf)

Definition at line 419 of file TcpLogger.cc.

References SquidConfig::buffered_logs, Config, Flush(), and SquidConfig::onoff.

Referenced by Open().

◆ flush()

void Log::TcpLogger::flush ( )

Definition at line 112 of file TcpLogger.cc.

References bufferedSize, flushDebt, and writeIfNeeded().

Referenced by endGracefully().

◆ Flush()

void Log::TcpLogger::Flush ( Logfile lf)

Definition at line 400 of file TcpLogger.cc.

References StillLogging().

Referenced by EndLine(), and Open().

◆ handleClosure()

void Log::TcpLogger::handleClosure ( const CommCloseCbParams io)

This is our comm_close_handler. It is called when some external force (e.g., reconfigure or shutdown) is closing the connection (rather than us).

Definition at line 366 of file TcpLogger.cc.

References assert, closer, conn, AsyncJob::inCall, AsyncJob::mustStop(), and NULL.

Referenced by connectDone().

◆ logRecord()

void Log::TcpLogger::logRecord ( const char *  buf,
size_t  len 

Definition at line 119 of file TcpLogger.cc.

References appendRecord(), and writeIfNeeded().

◆ mustStop()

void AsyncJob::mustStop ( const char *  aReason)

Definition at line 69 of file AsyncJob.cc.

References debugs, AsyncJob::inCall, Must, NULL, AsyncJob::stopReason, and AsyncJob::typeName.

Referenced by HttpStateData::abortAll(), Ftp::Client::abortAll(), Comm::TcpAcceptor::acceptOne(), Adaptation::Ecap::XactionRep::adaptationAborted(), Adaptation::AccessCheck::callBack(), AsyncJob::callException(), Security::PeerConnector::connectionClosed(), HttpStateData::continueAfterParsingHeader(), Ftp::Client::ctrlClosed(), Adaptation::Iterator::handleAdaptationBlock(), Adaptation::Iterator::handleAdaptationError(), handleClosure(), Adaptation::Icap::Xaction::handleCommClosed(), Http::Tunneler::handleConnectionClosure(), Mgr::Forwarder::handleError(), Ipc::Forwarder::handleError(), Ipc::Forwarder::handleException(), Ipc::Inquirer::handleException(), HttpStateData::handleMoreRequestBodyAvailable(), Ipc::Inquirer::handleRemoteAck(), Ipc::Forwarder::handleTimeout(), HttpStateData::httpStateConnClosed(), HttpStateData::httpTimeout(), Comm::ConnOpener::noteAbort(), Adaptation::Icap::ModXact::noteBodyConsumerAborted(), Snmp::Forwarder::noteCommClosed(), Snmp::Inquirer::noteCommClosed(), Mgr::Inquirer::noteCommClosed(), Mgr::Forwarder::noteCommClosed(), Mgr::StoreToCommWriter::noteCommClosed(), Adaptation::Icap::Xaction::noteCommRead(), Rock::HeaderUpdater::noteDoneReading(), Adaptation::Iterator::noteInitiatorAborted(), Adaptation::Icap::Xaction::noteInitiatorAborted(), Adaptation::Ecap::XactionRep::noteInitiatorAborted(), HttpStateData::readReply(), Comm::ConnOpener::sendAnswer(), Rock::Rebuild::start(), Security::PeerConnector::start(), HttpStateData::start(), Ipc::UdsSender::timedout(), and HttpStateData::wroteLast().

◆ Open()

◆ Rotate()

void Log::TcpLogger::Rotate ( Logfile lf,
const int16_t   

Definition at line 426 of file TcpLogger.cc.

Referenced by Open().

◆ Start()

◆ start()

void Log::TcpLogger::start ( )

Reimplemented from AsyncJob.

Definition at line 68 of file TcpLogger.cc.

References doConnect().

◆ StartLine()

void Log::TcpLogger::StartLine ( Logfile lf)

Definition at line 414 of file TcpLogger.cc.

Referenced by Open().

◆ status()

◆ StillLogging()

Log::TcpLogger * Log::TcpLogger::StillLogging ( Logfile lf)

Converts Logfile into a pointer to a valid TcpLogger job or, if the logger job has quit, into a nill pointer

Definition at line 392 of file TcpLogger.cc.

References Logfile::data, and NULL.

Referenced by Close(), Flush(), Open(), and WriteLine().

◆ swanSong()

void Log::TcpLogger::swanSong ( )

Reimplemented from AsyncJob.

Definition at line 96 of file TcpLogger.cc.

References disconnect(), and AsyncJob::swanSong().

◆ toCbdata()

virtual void* CbdataParent::toCbdata ( )
pure virtualinherited

◆ writeDone()

◆ writeIfNeeded()

void Log::TcpLogger::writeIfNeeded ( )

Definition at line 127 of file TcpLogger.cc.

References buffers, flushDebt, and writeIfPossible().

Referenced by connectDone(), flush(), logRecord(), and writeDone().

◆ writeIfPossible()

void Log::TcpLogger::writeIfPossible ( )

◆ WriteLine()

void Log::TcpLogger::WriteLine ( Logfile lf,
const char *  buf,
size_t  len 

Definition at line 407 of file TcpLogger.cc.

References StillLogging().

Referenced by Open().

Member Data Documentation

◆ bufferCapacity

size_t Log::TcpLogger::bufferCapacity

Definition at line 94 of file TcpLogger.h.

Referenced by canFit(), and TcpLogger().

◆ BufferCapacityMin

const size_t Log::TcpLogger::BufferCapacityMin = 2*Log::TcpLogger::IoBufSize

Definition at line 86 of file TcpLogger.h.

Referenced by TcpLogger().

◆ bufferedSize

size_t Log::TcpLogger::bufferedSize

Definition at line 95 of file TcpLogger.h.

Referenced by appendChunk(), canFit(), doneAll(), flush(), writeDone(), and writeIfPossible().

◆ buffers

std::list<MemBlobPointer> Log::TcpLogger::buffers

Definition at line 93 of file TcpLogger.h.

Referenced by appendChunk(), writeDone(), writeIfNeeded(), and writeIfPossible().

◆ closer

AsyncCall::Pointer Log::TcpLogger::closer

Definition at line 104 of file TcpLogger.h.

Referenced by connectDone(), disconnect(), and handleClosure().

◆ conn

Comm::ConnectionPointer Log::TcpLogger::conn

◆ connectFailures

uint64_t Log::TcpLogger::connectFailures

Definition at line 106 of file TcpLogger.h.

Referenced by connectDone(), and doneAll().

◆ dieOnError

bool Log::TcpLogger::dieOnError

Whether this job must kill Squid on the first unrecoverable error. Note that we may be able to recover from a failure to connect, but we cannot recover from forgetting (dropping) a record while connecting.

Definition at line 91 of file TcpLogger.h.

Referenced by canFit().

◆ drops

uint64_t Log::TcpLogger::drops

Definition at line 107 of file TcpLogger.h.

Referenced by appendRecord(), and canFit().

◆ flushDebt

size_t Log::TcpLogger::flushDebt

Definition at line 96 of file TcpLogger.h.

Referenced by flush(), writeDone(), and writeIfNeeded().

◆ id

const InstanceId<AsyncJob> AsyncJob::id

Definition at line 72 of file AsyncJob.h.

◆ inCall

◆ IoBufSize

const size_t Log::TcpLogger::IoBufSize = 2*MAX_URL

Definition at line 85 of file TcpLogger.h.

Referenced by appendChunk(), and appendRecord().

◆ quitOnEmpty

bool Log::TcpLogger::quitOnEmpty

Definition at line 98 of file TcpLogger.h.

Referenced by doneAll(), and endGracefully().

◆ reconnectScheduled

bool Log::TcpLogger::reconnectScheduled

Definition at line 99 of file TcpLogger.h.

Referenced by connectDone(), and delayedReconnect().

◆ remote

Ip::Address Log::TcpLogger::remote

Definition at line 103 of file TcpLogger.h.

Referenced by canFit(), connectDone(), doConnect(), and TcpLogger().

◆ stopReason

const char* AsyncJob::stopReason

◆ typeName

◆ writeScheduled

bool Log::TcpLogger::writeScheduled

Definition at line 100 of file TcpLogger.h.

Referenced by appendChunk(), writeDone(), writeIfPossible(), and ~TcpLogger().

The documentation for this class was generated from the following files:






Web Site Translations