Loading...
Searching...
No Matches
ASSA::RemoteLogger Class Reference

`#include <RemoteLogger.h>`

Inheritance diagram for ASSA::RemoteLogger:

## Public Member Functions

| RemoteLogger ()
virtual int | open ()
| Called by Connector upon establishing connection.
virtual int | handle_close (int fd_)
| Called by Reactor when we close connection with log_close().
virtual int | log_open (const char *appname_, const char *logfname_, u_long groups_, u_long maxsize_, Reactor *reactor_)
| Calling results into sending SIGN-ON message.
virtual int | log_close (void)
| Close connection to the assa-logd.
virtual void | log_resync (void)
| Flush output buffer.
virtual int | log_msg (Group g_, size_t indent_level_, const string &func_name_, size_t expected_sz_, const char *fmt_, va_list)
virtual int | log_func (Group g_, size_t indent_level_, const string &func_name_, marker_t type_)
Public Member Functions inherited from ASSA::Logger_Impl
| Logger_Impl ()
virtual | ~Logger_Impl ()
void | enable_group (Group g_)
void | disable_group (Group g_)
void | enable_groups (u_long g_)
void | disable_groups (u_long g_)
void | enable_all_groups (void)
void | disable_all_groups (void)
bool | group_enabled (Group g_) const
void | enable_timestamp (void)
void | disable_timestamp (void)
bool | timestamp_enabled (void) const
void | set_timezone (int zone_)
void | set_indent_step (u_short step_)
u_short | get_indent_step (void) const
virtual int | log_open (u_long groups_)
| Open StdErr Logger.
virtual int | log_open (const char *logfname_, u_long groups_, u_long maxsize_)
| Open File Logger.
Public Member Functions inherited from ASSA::ServiceHandler< ASSA::IPv4Socket >
| ServiceHandler ()
| Default constructor.
virtual | ~ServiceHandler ()
| Destructor closes and deletes PEER_STREAM.
virtual void | close (void)
| Pure virtual method defined by subclass.
| operator ASSA::IPv4Socket & ()
| Conversion operator to type PEER_STREAM &.
ASSA::IPv4Socket & | get_stream ()
| Return referenct to underlying PEER_STREAM.
Public Member Functions inherited from ASSA::EventHandler
| EventHandler ()
| Constructor.
virtual | ~EventHandler ()
| Virtual destructor.
virtual int | handle_read (int fd)
| Read event callback.
virtual int | handle_write (int fd)
| Write handler callback.
virtual int | handle_except (int fd)
| Exception handler callback.
virtual int | handle_timeout (TimerId tid)
| Timeout handler callback.
virtual int | handle_signal (int signum_)
| Signal handler callback.
virtual void | resetState (void)
| A hook for derived class to reset internal state as needed.
void | set_id (const std::string &id_)
| Set EventHandler ID.
std::string | get_id () const
| Retrieve EventHandler ID.

## Private Types

enum | state_t { opened , closed }
enum | msg_t { SIGN_ON = 0 , SIGN_OFF , LOG_MSG }

## Private Member Functions

| RemoteLogger (const RemoteLogger &)
RemoteLogger & | operator= (const RemoteLogger &)

## Private Attributes

state_t | m_state
Reactor * | m_reactor
bool | m_recursive_call
| If true, recursive call is in progress.

## Additional Inherited Members

Static Public Attributes inherited from ASSA::Logger_Impl
static const unsigned int | LOGGER_MAXLINE = 6660
| Maximum length of the formatted message.
Protected Member Functions inherited from ASSA::Logger_Impl
virtual u_short | add_timestamp (ostream &sink_)
virtual u_short | indent_func_name (ostream &sink_, const string &funcname_, size_t indent_level_, marker_t type_)
char * | format_msg (size_t expected_sz_, const char *fmt_, va_list vap_, bool &release_)
| Format and put the message in the buffer.
Protected Attributes inherited from ASSA::Logger_Impl
u_short | m_indent_step
| Indentation step.
u_long | m_groups
| Enabled groups.
string | m_logfname
| Log file name.
bool | m_tmflg
| Timestamp on/off flag.
int | m_tz
| Timezone: 0-GMT, 1-Local.
Protected Attributes inherited from ASSA::ServiceHandler< ASSA::IPv4Socket >
ASSA::IPv4Socket * | m_peerStream
| Concrete Socket instance.
Protected Attributes inherited from ASSA::EventHandler
std::string | m_id
Static Protected Attributes inherited from ASSA::Logger_Impl
static char | m_msgbuf [LOGGER_MAXLINE]
| Static buffer for formatted message.

## Detailed Description

Definition at line 38 of file RemoteLogger.h.

## Member Enumeration Documentation

## msg_t

enum ASSA::RemoteLogger::msg_t

private

Enumerator
SIGN_ON |
SIGN_OFF |
LOG_MSG |

Definition at line 83 of file RemoteLogger.h.

{ SIGN_ON = 0, SIGN_OFF, LOG_MSG };
ASSA::RemoteLogger::LOG_MSG
@ LOG_MSG
Definition RemoteLogger.h:83
ASSA::RemoteLogger::SIGN_OFF
@ SIGN_OFF
Definition RemoteLogger.h:83
ASSA::RemoteLogger::SIGN_ON
@ SIGN_ON
Definition RemoteLogger.h:83

## state_t

enum ASSA::RemoteLogger::state_t

private

Enumerator
opened |
closed |

Definition at line 82 of file RemoteLogger.h.

{ opened, closed };
ASSA::RemoteLogger::closed
@ closed
Definition RemoteLogger.h:82
ASSA::RemoteLogger::opened
@ opened
Definition RemoteLogger.h:82

## Constructor & Destructor Documentation

## RemoteLogger() [1/2]

RemoteLogger::RemoteLogger | ( |  | ) |

Definition at line 29 of file RemoteLogger.cpp.

:
m_state (closed),
m_recursive_call (false)
{
// no-op
}
ASSA::RemoteLogger::m_recursive_call
bool m_recursive_call
If true, recursive call is in progress.
Definition RemoteLogger.h:89
ASSA::RemoteLogger::m_state
state_t m_state
Definition RemoteLogger.h:85

References closed, m_recursive_call, and m_state.

Referenced by operator=(), and RemoteLogger().

## RemoteLogger() [2/2]

ASSA::RemoteLogger::RemoteLogger | ( | const RemoteLogger & |  | ) |

private

References RemoteLogger().

## Member Function Documentation

## handle_close()

int RemoteLogger::handle_close | ( | int | fd_ | ) |

virtual

Called by Reactor when we close connection with log_close().

Reimplemented from ASSA::EventHandler.

Definition at line 104 of file RemoteLogger.cpp.

{
m_state = closed;
m_logfname.empty ();
return 0;
}
ASSA::Logger_Impl::m_logfname
string m_logfname
Log file name.
Definition Logger_Impl.h:242

References closed, ASSA::Logger_Impl::m_logfname, and m_state.

## log_close()

int RemoteLogger::log_close | ( | void |  | ) |

virtual

Close connection to the assa-logd.

Send SIGN_OFF message to the log server and stop data processing. We are managed by Logger class.

Implements ASSA::Logger_Impl.

Definition at line 88 of file RemoteLogger.cpp.

{
if (m_state == opened) {
m_recursive_call = true;
get_stream () << 1234567890 << SIGN_OFF << 0 << ASSA::flush;
m_reactor->removeHandler (this, READ_EVENT);
m_recursive_call = false;
}
return 0;
}
ASSA::RemoteLogger::m_reactor
Reactor * m_reactor
Definition RemoteLogger.h:86
ASSA::ServiceHandler< ASSA::IPv4Socket >::get_stream
ASSA::IPv4Socket & get_stream()
Definition ServiceHandler.h:100
ASSA::READ_EVENT
@ READ_EVENT
Notify when there will be at least 1 byte available for reading from IO channel without blocking .
Definition EventHandler.h:36
ASSA::flush
Socket & flush(Socket &os_)
flush manipulator.
Definition Socket.h:587

References ASSA::flush(), ASSA::ServiceHandler< ASSA::IPv4Socket >::get_stream(), m_reactor, m_recursive_call, m_state, opened, ASSA::READ_EVENT, and SIGN_OFF.

## log_func()

int RemoteLogger::log_func | ( | Group | g_,
|  | size_t | indent_level_,
|  | const string & | func_name_,
|  | marker_t | type_ )

virtual

Header + body (preamble;LOG_MSG;length;msg)

Implements ASSA::Logger_Impl.

Definition at line 174 of file RemoteLogger.cpp.

{
if (m_recursive_call) {
return 0;
}
if (m_state == closed) {
return -1;
}
if (! group_enabled (groups_)) {
return 0;
}
std::ostringstream os;
add_timestamp (os);
indent_func_name (os, func_name_, indent_level_, type_);
os << ((type_ == FUNC_ENTRY) ? "---v---\n" : "---^---\n");
if (get_stream ().good ()) {
m_recursive_call = true;
get_stream () << 1234567890 << LOG_MSG << Socket::xdr_length (os.str ())
<< os.str () << ASSA::flush;
m_recursive_call = false;
}
else {
m_state = closed;
}
return 0;
}
ASSA::Logger_Impl::indent_func_name
virtual u_short indent_func_name(ostream &sink_, const string &funcname_, size_t indent_level_, marker_t type_)
Definition Logger_Impl.cpp:54
ASSA::Logger_Impl::group_enabled
bool group_enabled(Group g_) const
Definition Logger_Impl.h:164
ASSA::Logger_Impl::add_timestamp
virtual u_short add_timestamp(ostream &sink_)
Definition Logger_Impl.cpp:35
ASSA::Socket::xdr_length
static size_t xdr_length(const std::string &s_)
Give the true length of the XDR-encoded STL string.
Definition Socket.h:343
ASSA::FUNC_ENTRY
@ FUNC_ENTRY
Definition LogMask.h:69

References ASSA::Logger_Impl::add_timestamp(), closed, ASSA::flush(), ASSA::FUNC_ENTRY, ASSA::ServiceHandler< ASSA::IPv4Socket >::get_stream(), ASSA::Logger_Impl::group_enabled(), ASSA::Logger_Impl::indent_func_name(), LOG_MSG, m_recursive_call, m_state, and ASSA::Socket::xdr_length().

## log_msg()

int RemoteLogger::log_msg | ( | Group | g_,
|  | size_t | indent_level_,
|  | const string & | func_name_,
|  | size_t | expected_sz_,
|  | const char * | fmt_,
|  | va_list | msg_list_ )

virtual

Header + body (preamble;LOG_MSG;length;msg)

Implements ASSA::Logger_Impl.

Definition at line 124 of file RemoteLogger.cpp.

{
if (m_recursive_call) {
return 0;
}
if (m_state == closed) {
return -1;
}
if (!group_enabled (groups_)) {
return 0;
}
std::ostringstream os;
add_timestamp (os);
indent_func_name (os, func_name_, indent_level_, FUNC_MSG);
bool release = false;
char* msgbuf_ptr = format_msg (expected_sz_, fmt_, msg_list_, release);
if (msgbuf_ptr == NULL) {
return -1; // failed to format
}
os << msgbuf_ptr;
if (release) {
delete [] msgbuf_ptr;
}
if (get_stream ()) {
m_recursive_call = true;
Assure_exit (os.str ().length () != 0);
get_stream () << 1234567890 << LOG_MSG << Socket::xdr_length (os.str ())
<< os.str () << ASSA::flush;
m_recursive_call = false;
}
else {
m_state = closed;
}
return 0;
}
Assure_exit
#define Assure_exit(exp_)
Macro that makes program exit if assert fails.
Definition Assure.h:39
ASSA::Logger_Impl::format_msg
char * format_msg(size_t expected_sz_, const char *fmt_, va_list vap_, bool &release_)
Format and put the message in the buffer.
Definition Logger_Impl.cpp:86
ASSA::FUNC_MSG
@ FUNC_MSG
Definition LogMask.h:68

References ASSA::Logger_Impl::add_timestamp(), Assure_exit, closed, ASSA::flush(), ASSA::Logger_Impl::format_msg(), ASSA::FUNC_MSG, ASSA::ServiceHandler< ASSA::IPv4Socket >::get_stream(), ASSA::Logger_Impl::group_enabled(), ASSA::Logger_Impl::indent_func_name(), LOG_MSG, m_recursive_call, m_state, and ASSA::Socket::xdr_length().

## log_open()

int RemoteLogger::log_open | ( | const char * | appname_,
|  | const char * | logfname_,
|  | u_long | groups_,
|  | u_long | maxsize_,
|  | Reactor * | reactor_ )

virtual

Calling results into sending SIGN-ON message.

Put stream in a blocking mode. Otherwise, fast clients can override log server.

Send SIGN_ON message to the log server.

Header + Body

Reimplemented from ASSA::Logger_Impl.

Definition at line 45 of file RemoteLogger.cpp.

{
if (m_recursive_call) {
return 0;
}
m_recursive_call = true;
if (m_state == opened) {
return 0;
}
m_logfname = logfname_;
m_groups = groups_;
m_reactor = reactor_;
m_reactor->registerIOHandler (this, get_stream ().getHandler(),
ASSA::READ_EVENT);
get_stream ().turnOptionOff (Socket::nonblocking);
size_t len = sizeof (maxsize_) +
Socket::xdr_length (appname_) +
Socket::xdr_length (logfname_);
get_stream () << 1234567890 << SIGN_ON << len
<< maxsize_ << appname_ << logfname_ << ASSA::flush;
m_state = opened;
m_recursive_call = false;
return 0;
}
ASSA::Logger_Impl::m_groups
u_long m_groups
Enabled groups.
Definition Logger_Impl.h:239
ASSA::Socket::turnOptionOff
bool turnOptionOff(opt_t opt_)
Disable socket option.
Definition Socket.cpp:204
ASSA::Socket::nonblocking
@ nonblocking
Set Socket to a non-blocking mode (O_RDWR|O_NONBLOCK).
Definition Socket.h:115

References ASSA::flush(), ASSA::ServiceHandler< ASSA::IPv4Socket >::get_stream(), ASSA::Logger_Impl::m_groups, ASSA::Logger_Impl::m_logfname, m_reactor, m_recursive_call, m_state, ASSA::Socket::nonblocking, opened, ASSA::READ_EVENT, SIGN_ON, ASSA::Socket::turnOptionOff(), and ASSA::Socket::xdr_length().

## log_resync()

void RemoteLogger::log_resync | ( | void |  | ) |

virtual

Flush output buffer.

Reimplemented from ASSA::Logger_Impl.

Definition at line 113 of file RemoteLogger.cpp.

{
if (m_state == opened) {
m_recursive_call = true;
get_stream () << ASSA::flush;
m_recursive_call = false;
}
}

References ASSA::flush(), ASSA::ServiceHandler< ASSA::IPv4Socket >::get_stream(), m_recursive_call, m_state, and opened.

## open()

int RemoteLogger::open | ( | void |  | ) |

virtual

Called by Connector upon establishing connection.

Implements ASSA::ServiceHandler< ASSA::IPv4Socket >.

Definition at line 38 of file RemoteLogger.cpp.

{
return 0;
}

## operator=()

RemoteLogger & ASSA::RemoteLogger::operator= | ( | const RemoteLogger & |  | ) |

private

References RemoteLogger().

## Member Data Documentation

## m_reactor

Reactor* ASSA::RemoteLogger::m_reactor

private

Definition at line 86 of file RemoteLogger.h.

Referenced by log_close(), and log_open().

## m_recursive_call

bool ASSA::RemoteLogger::m_recursive_call

private

If true, recursive call is in progress.

Definition at line 89 of file RemoteLogger.h.

Referenced by log_close(), log_func(), log_msg(), log_open(), log_resync(), and RemoteLogger().

## m_state

state_t ASSA::RemoteLogger::m_state

private

Definition at line 85 of file RemoteLogger.h.

Referenced by handle_close(), log_close(), log_func(), log_msg(), log_open(), log_resync(), and RemoteLogger().

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

- RemoteLogger.h
- RemoteLogger.cpp