reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
SysLogBuf.cxx
Go to the documentation of this file.
1#include <cstdio>
2#include "rutil/ResipAssert.h"
3#include "rutil/SysLogBuf.hxx"
4#include "rutil/Log.hxx"
5
6#ifndef EOF
7# define EOF (-1)
8#endif
9
11
13 : mLevel(Log::Debug),
14 mAppName(""),
15 mFacility(LOG_DAEMON)
16{
17 init();
18}
19
20SysLogBuf::SysLogBuf (const resip::Data& ident, int facility)
21 : mLevel(Log::Debug),
22 mAppName(ident),
23 mFacility(facility)
24{
25 init();
26}
27
28void
29SysLogBuf::init()
30{
31#if !defined(WIN32)
32 setp(buffer,buffer+Size);
33 const char* _ident = 0;
34 if(!mAppName.empty())
35 {
36 _ident = mAppName.c_str();
37 }
38 openlog (_ident, LOG_NDELAY | LOG_PID, mFacility);
39#endif
40}
41
45
46int
48{
49#if !defined(WIN32)
50 // Default to debug level for Stack, Debug and unrecognised values
51 int _level = LOG_DEBUG;
52 // For efficiency, we check mLevel in decreasing order of frequency,
53 // anticipating that Stack is the most common and Crit is the least
54 // common.
55 switch(mLevel)
56 {
57 case Log::Stack:
58 case Log::Debug:
59 // This is just here to avoid traversing the rest
60 // of the switch block for every Stack or Debug message.
61 // They will just be logged with the default LOG_DEBUG
62 // specified above.
63 break;
64 case Log::Info:
65 _level = LOG_INFO;
66 break;
67 case Log::Warning:
68 _level = LOG_WARNING;
69 break;
70 case Log::Err:
71 _level = LOG_ERR;
72 break;
73 case Log::Crit:
74 _level = LOG_CRIT;
75 break;
76 default:
77 // just let it use the default value defined above
78 break;
79 }
80 *(pptr()) = 0;
81 syslog (mFacility | _level, "%s", pbase());
82 // Set mLevel back to the default level for the next log entry
83 // in case it is not explicitly specified next time.
84 mLevel = Log::Debug;
85 setp(buffer, buffer+Size);
86#else
87 resip_assert(0);
88#endif
89 return 0;
90}
91
92int
94{
95 sync();
96 if (c != EOF)
97 {
98 *pptr() = static_cast<unsigned char>(c);
99 pbump(1);
100 }
101 return c;
102}
103
104std::ostream& resip::operator<< (std::ostream& os, const resip::Log::Level& level)
105{
106 // FIXME - we should probably find a more precise way to make sure
107 // that this can never be done for the wrong type of stream.
108 // For now, we rely on Log.cxx checking if mLogger is of type Syslog
109 // and not sending Level to the stream otherwise.
110 static_cast<SysLogBuf *>(os.rdbuf())->mLevel = level;
111 return os;
112}
113
114/* ====================================================================
115 * The Vovida Software License, Version 1.0
116 *
117 * Copyright (c) 2000-2005 Vovida Networks, Inc. All rights reserved.
118 *
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 *
123 * 1. Redistributions of source code must retain the above copyright
124 * notice, this list of conditions and the following disclaimer.
125 *
126 * 2. Redistributions in binary form must reproduce the above copyright
127 * notice, this list of conditions and the following disclaimer in
128 * the documentation and/or other materials provided with the
129 * distribution.
130 *
131 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
132 * and "Vovida Open Communication Application Library (VOCAL)" must
133 * not be used to endorse or promote products derived from this
134 * software without prior written permission. For written
135 * permission, please contact vocal@vovida.org.
136 *
137 * 4. Products derived from this software may not be called "VOCAL", nor
138 * may "VOCAL" appear in their name, without prior written
139 * permission of Vovida Networks, Inc.
140 *
141 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
142 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
143 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
144 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
145 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
146 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
147 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
148 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
149 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
150 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
151 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
152 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
153 * DAMAGE.
154 *
155 * ====================================================================
156 *
157 * This software consists of voluntary contributions made by Vovida
158 * Networks, Inc. and many individuals on behalf of Vovida Networks,
159 * Inc. For more information on Vovida Networks, Inc., please see
160 * <http://www.vovida.org/>.
161 *
162 */
#define resip_assert(x)
This file needs to work for both C and C++ code.
#define EOF
Definition SysLogBuf.cxx:7
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
const char * c_str() const
Returns a null-terminated string representing.
Definition Data.cxx:1097
bool empty() const noexcept
Checks whether the Data is empty.
Definition Data.hxx:591
Singleton that handles logging calls.
Definition Log.hxx:51
@ Debug
Definition Log.hxx:84
@ Stack
Definition Log.hxx:86
@ Warning
Definition Log.hxx:82
virtual ~SysLogBuf()
Definition SysLogBuf.cxx:42
int overflow(int ch)
Definition SysLogBuf.cxx:93
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
void list()
Definition userAdmin.cxx:66