1 /*
2 * This file is part of Licq, an instant messaging client for UNIX.
3 * Copyright (C) 2010 Licq Developers <licq-dev@googlegroups.com>
4 *
5 * Please refer to the COPYRIGHT file distributed with this source
6 * distribution for the names of the individual contributors.
7 *
8 * Licq is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * Licq is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with Licq; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "adjustablelogsink.h"
24
25 #include <licq/thread/mutexlocker.h>
26
27 const unsigned int AllLevelsMask = (1 << (Licq::Log::Debug + 1)) - 1;
28 extern const unsigned int PacketBit = 0x1000;
29
30 using namespace LicqDaemon;
31 using Licq::MutexLocker;
32
AdjustableLogSink()33 AdjustableLogSink::AdjustableLogSink()
34 : myLogLevels(0)
35 {
36 // Empty
37 }
38
isLogging(Licq::Log::Level level) const39 bool AdjustableLogSink::isLogging(Licq::Log::Level level) const
40 {
41 MutexLocker locker(myMutex);
42 return myLogLevels & (1 << level);
43 }
44
isLoggingPackets() const45 bool AdjustableLogSink::isLoggingPackets() const
46 {
47 MutexLocker locker(myMutex);
48 return myLogLevels & PacketBit;
49 }
50
setLogLevel(Licq::Log::Level level,bool enable)51 void AdjustableLogSink::setLogLevel(Licq::Log::Level level, bool enable)
52 {
53 MutexLocker locker(myMutex);
54 if (enable)
55 myLogLevels |= (1 << level);
56 else
57 myLogLevels &= ~(1 << level);
58 }
59
setLogPackets(bool enable)60 void AdjustableLogSink::setLogPackets(bool enable)
61 {
62 MutexLocker locker(myMutex);
63 if (enable)
64 myLogLevels |= PacketBit;
65 else
66 myLogLevels &= ~PacketBit;
67 }
68
setAllLogLevels(bool enable)69 void AdjustableLogSink::setAllLogLevels(bool enable)
70 {
71 MutexLocker locker(myMutex);
72 if (enable)
73 myLogLevels |= AllLevelsMask;
74 else
75 myLogLevels &= ~AllLevelsMask;
76 }
77
setLogLevelsFromBitmask(unsigned int levels)78 void AdjustableLogSink::setLogLevelsFromBitmask(unsigned int levels)
79 {
80 MutexLocker locker(myMutex);
81 myLogLevels = levels & (AllLevelsMask | PacketBit);
82 }
83
getLogLevelsBitmask() const84 unsigned int AdjustableLogSink::getLogLevelsBitmask() const
85 {
86 MutexLocker locker(myMutex);
87 return myLogLevels;
88 }
89