libassa 3.5.1
StdOutLogger.cpp
Go to the documentation of this file.
1// -*- c++ -*-
2//------------------------------------------------------------------------------
3// StdOutLogger.cpp
4//------------------------------------------------------------------------------
5// $Id: StdOutLogger.cpp,v 1.4 2006/07/20 02:30:54 vlg Exp $
6//------------------------------------------------------------------------------
7// Copyright (c) 2001 by Vladislav Grinchenko
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Library General Public
11// License as published by the Free Software Foundation; either
12// version 2 of the License, or (at your option) any later version.
13//
14//------------------------------------------------------------------------------
15// Created: 10/31/2001
16//------------------------------------------------------------------------------
17#include <stdio.h>
18#include <stdarg.h> // vsprintf(3)
19#include <string>
20#include <iomanip>
21
22#include "assa/StdOutLogger.h"
23
24using namespace ASSA;
25
26int
27StdOutLogger::
28log_msg (Group g_,
29 size_t indent_level_,
30 const string& func_name_,
31 size_t expected_sz_,
32 const char* fmt_,
33 va_list msg_list_)
34{
35 bool release = false;
36 char* msgbuf_ptr = NULL;
37
38 if (! group_enabled (g_)) {
39 return 0;
40 }
41
42 add_timestamp (std::cerr);
43 indent_func_name (std::cerr, func_name_, indent_level_, FUNC_MSG);
44
45 msgbuf_ptr = format_msg (expected_sz_, fmt_, msg_list_, release);
46
47 if (msgbuf_ptr == NULL) {
48 return -1; // failed to format
49 }
50 std::cout << msgbuf_ptr;
51
52 if (release) {
53 delete [] msgbuf_ptr;
54 }
55 return 0;
56}
57
58int
60log_func (Group g_,
61 size_t indent_level_,
62 const string& func_name_,
63 marker_t type_)
64{
65 if (! group_enabled (g_)) {
66 return 0;
67 }
68
69 add_timestamp (std::cerr);
70 indent_func_name (std::cout, func_name_, indent_level_, type_);
71
72 if (type_ == FUNC_ENTRY) {
73 std::cout << "---v---\n";
74 }
75 else if (type_ == FUNC_EXIT) {
76 std::cout << "---^---\n";
77 }
78
79 return 0;
80}
81
StdOutLogger implements Logger as standard output.
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
virtual u_short indent_func_name(ostream &sink_, const string &funcname_, size_t indent_level_, marker_t type_)
Definition: Logger_Impl.cpp:54
bool group_enabled(Group g_) const
Definition: Logger_Impl.h:164
virtual u_short add_timestamp(ostream &sink_)
Definition: Logger_Impl.cpp:35
virtual int log_func(Group g_, size_t indent_level_, const string &func_name_, marker_t type_)
Definition: Acceptor.h:40
marker_t
Definition: LogMask.h:67
@ FUNC_ENTRY
Definition: LogMask.h:69
@ FUNC_MSG
Definition: LogMask.h:68
@ FUNC_EXIT
Definition: LogMask.h:70
Group
Definition: LogMask.h:25