1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
13 ******************************************************************************/
14 #include "LoggingBits.hh"
20 void Logging_Bits::clear()
22 memset( bits
, 0, sizeof(bits
) );
26 void Logging_Bits::merge( const Logging_Bits
& other
)
28 for( size_t i
= 0; i
< TTCN_Logger::NUMBER_OF_LOGSEVERITIES
; ++i
)
30 bits
[i
] = bits
[i
] || other
.bits
[i
];
34 void Logging_Bits::add_sev( TTCN_Logger::Severity sev
)
37 assert(sev
< TTCN_Logger::NUMBER_OF_LOGSEVERITIES
);
38 // Note that the assert and the comparison below are different.
39 // 0==LOG_NOTHING which is valid but it means nothing to do.
40 if (sev
> 0 && sev
< TTCN_Logger::NUMBER_OF_LOGSEVERITIES
) {
46 bool Logging_Bits::operator==( const Logging_Bits
& other
) const
48 return memcmp( bits
, other
.bits
, sizeof(bits
) ) == 0;
53 expstring_t
Logging_Bits::describe() const
55 expstring_t result
= memptystr(); // not NULL
56 size_t categ
= 1; // skip LOG_NOTHING
58 // First check whether the bits that make up LOG_ALL are all set
59 // (by comparing with log_all, which has those bits set).
60 // Remember to skip +1 for LOG_NOTHING
61 if( memcmp(bits
+1, log_all
.bits
+1, TTCN_Logger::WARNING_UNQUALIFIED
) == 0 )
63 result
= mputstr(result
, "LOG_ALL");
64 categ
= TTCN_Logger::number_of_categories
- 2; // only MATCHING and DEBUG left
67 for( ; categ
< TTCN_Logger::number_of_categories
; ++categ
) {
68 // sev_categories[categ-1] is the non-inclusive lower end
69 // sev_categories[categ ] is the inclusive upper end
70 // these two form a half-closed range (the opposite of what the STL uses)
72 size_t low_inc
= TTCN_Logger::sev_categories
[categ
-1] + 1;
73 size_t high_inc
= TTCN_Logger::sev_categories
[categ
];
75 const bool * first
= bits
+ low_inc
;
76 size_t length
= high_inc
- low_inc
+ 1;
77 assert(length
< TTCN_Logger::NUMBER_OF_LOGSEVERITIES
-1);
78 // Comparing a segment of our bits with the "all 1s" of log_everything
79 if( memcmp(first
, log_everything
.bits
+1, length
) == 0 ) {
80 // all bits for this main severity are on
81 if( result
[0] != '\0' ) {
82 // string not empty, append separator
83 result
= mputstr(result
, " | ");
85 // append main severity name
86 result
= mputstr(result
, TTCN_Logger::severity_category_names
[categ
]);
89 // not all bits are on, have to append them one by one
90 for( size_t subcat
= low_inc
; subcat
<= high_inc
; ++subcat
) {
92 if( result
[0] != '\0' ) {
93 // string not empty, append separator
94 result
= mputstr(result
, " | ");
96 result
= mputstr(result
, TTCN_Logger::severity_category_names
[categ
]);
97 result
= mputc (result
, '_');
98 result
= mputstr(result
, TTCN_Logger::severity_subcategory_names
[subcat
]);
104 if( result
[0] == '\0' ) {
105 result
= mputstr(result
, "LOG_NOTHING");
110 /********************** "Well-known" values **********************/
112 const Logging_Bits
Logging_Bits::log_nothing
= { {0} };
114 const Logging_Bits
Logging_Bits::log_all
= {
117 1,1,1,1, // DEFAULTOP
119 1,1,1,1,1,1, // EXECUTOR
123 1,1,1,1,1,1,1,1,1,1,1,1,1,1, // PORTEVENT
125 1,1,1,1,1,1, // TIMEROP
127 1,1,1,1, // VERDICTOP
129 0,0,0,0,0,0,0,0,0,0,0,0, // MATCHING
134 const Logging_Bits
Logging_Bits::log_everything
= {
135 { 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
136 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }
139 // TTCN_ERROR | TTCN_WARNING | TTCN_ACTION | TTCN_TESTCASE | TTCN_STATISTICS
140 const Logging_Bits
Logging_Bits::default_console_mask
= {
143 0,0,0,0, // DEFAULTOP
145 0,0,0,0,0,0, // EXECUTOR
149 0,0,0,0,0,0,0,0,0,0,0,0,0,0, // PORTEVENT
151 0,0,0,0,0,0, // TIMEROP
153 0,0,0,0, // VERDICTOP
155 0,0,0,0,0,0,0,0,0,0,0,0, // MATCHING