blob: 5db7f87306620674064fda7dc0e08b3bc5042b33 [file] [log] [blame]
dburgess82c46ff2011-10-07 02:40:51 +00001/*
Pau Espin Pedrol3da1f832018-02-20 20:01:10 +01002* Copyright (C) 2018 sysmocom - s.f.m.c. GmbH
dburgess82c46ff2011-10-07 02:40:51 +00003*
Pau Espin Pedrol21d03d32019-07-22 12:05:52 +02004* SPDX-License-Identifier: AGPL-3.0+
dburgess82c46ff2011-10-07 02:40:51 +00005*
6* This software is distributed under the terms of the GNU Affero Public License.
7* See the COPYING file in the main directory for details.
8*
9* This use of this software may be subject to additional restrictions.
10* See the LEGAL file in the main directory for details.
11
12 This program is free software: you can redistribute it and/or modify
13 it under the terms of the GNU Affero General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU Affero General Public License for more details.
21
22 You should have received a copy of the GNU Affero General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
24
25*/
26
27#include <string.h>
28#include <cstdio>
29#include <fstream>
30#include <string>
kurtis.heimerl00913d72012-12-16 06:08:18 +000031#include <stdarg.h>
Alexander Chemeris4793f462017-03-17 18:35:48 -070032#include <sys/time.h> // For gettimeofday
dburgess82c46ff2011-10-07 02:40:51 +000033
dburgess82c46ff2011-10-07 02:40:51 +000034#include "Logger.h"
kurtis.heimerl5a872472013-05-31 21:47:25 +000035#include "Threads.h" // pat added
dburgess82c46ff2011-10-07 02:40:51 +000036
dburgess82c46ff2011-10-07 02:40:51 +000037using namespace std;
38
Alexander Chemeris4793f462017-03-17 18:35:48 -070039std::ostream& operator<<(std::ostream& os, std::ostringstream& ss)
40{
41 return os << ss.str();
42}
dburgess82c46ff2011-10-07 02:40:51 +000043
dburgess82c46ff2011-10-07 02:40:51 +000044Log::~Log()
45{
Pau Espin Pedrol86be40b2018-09-03 15:22:50 +020046 int old_state;
Pau Espin Pedrol61837c02018-02-20 18:22:18 +010047 int mlen = mStream.str().size();
48 int neednl = (mlen==0 || mStream.str()[mlen-1] != '\n');
Pau Espin Pedrol3da1f832018-02-20 20:01:10 +010049 const char *fmt = neednl ? "%s\n" : "%s";
Pau Espin Pedrolc9202ab2019-07-01 20:13:32 +020050
51 log_mutex_lock_canceldisable(&old_state);
Pau Espin Pedrol3b78cbf2018-04-25 16:43:02 +020052 LOGPSRC(mCategory, mPriority, filename, line, fmt, mStream.str().c_str());
Pau Espin Pedrolc9202ab2019-07-01 20:13:32 +020053 log_mutex_unlock_canceldisable(old_state);
dburgess82c46ff2011-10-07 02:40:51 +000054}
55
dburgess82c46ff2011-10-07 02:40:51 +000056ostringstream& Log::get()
57{
dburgess82c46ff2011-10-07 02:40:51 +000058 return mStream;
59}
60
dburgess82c46ff2011-10-07 02:40:51 +000061// vim: ts=4 sw=4