< prev index next >

src/share/vm/logging/logTagSet.cpp

Print this page
rev 10661 : [mq]: 8145934
rev 10662 : imported patch 8145934.alternative


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 #include "precompiled.hpp"
  25 #include "logging/logDecorations.hpp"
  26 #include "logging/logLevel.hpp"

  27 #include "logging/logOutput.hpp"
  28 #include "logging/logTag.hpp"
  29 #include "logging/logTagSet.hpp"
  30 
  31 LogTagSet*  LogTagSet::_list      = NULL;
  32 size_t      LogTagSet::_ntagsets  = 0;
  33 
  34 // This constructor is called only during static initialization.
  35 // See the declaration in logTagSet.hpp for more information.
  36 LogTagSet::LogTagSet(LogTagType t0, LogTagType t1, LogTagType t2, LogTagType t3, LogTagType t4)
  37     : _next(_list) {
  38   _tag[0] = t0;
  39   _tag[1] = t1;
  40   _tag[2] = t2;
  41   _tag[3] = t3;
  42   _tag[4] = t4;
  43   for (_ntags = 0; _ntags < LogTag::MaxTags && _tag[_ntags] != LogTag::__NO_TAG; _ntags++) {
  44   }
  45   _list = this;
  46   _ntagsets++;


  57   LogDecorators new_decorators = decorator;
  58   for (LogOutputList::Iterator it = _output_list.iterator(); it != _output_list.end(); it++) {
  59     new_decorators.combine_with((*it)->decorators());
  60   }
  61   _decorators = new_decorators;
  62 }
  63 
  64 bool LogTagSet::has_output(const LogOutput* output) {
  65   for (LogOutputList::Iterator it = _output_list.iterator(); it != _output_list.end(); it++) {
  66     if (*it == output) {
  67       return true;
  68     }
  69   }
  70   return false;
  71 }
  72 
  73 void LogTagSet::log(LogLevelType level, const char* msg) {
  74   LogDecorations decorations(level, *this, _decorators);
  75   for (LogOutputList::Iterator it = _output_list.iterator(level); it != _output_list.end(); it++) {
  76     (*it)->write(decorations, msg);







  77   }
  78 }
  79 
  80 int LogTagSet::label(char* buf, size_t len, const char* separator) const {
  81   int tot_written = 0;
  82   for (size_t i = 0; i < _ntags; i++) {
  83     int written = jio_snprintf(buf + tot_written, len - tot_written, "%s%s",
  84                                (i == 0 ? "" : separator),
  85                                LogTag::name(_tag[i]));
  86     if (written < 0) {
  87       return -1;
  88     }
  89     tot_written += written;
  90   }
  91   return tot_written;
  92 }


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 #include "precompiled.hpp"
  25 #include "logging/logDecorations.hpp"
  26 #include "logging/logLevel.hpp"
  27 #include "logging/logMessageBuffer.hpp"
  28 #include "logging/logOutput.hpp"
  29 #include "logging/logTag.hpp"
  30 #include "logging/logTagSet.hpp"
  31 
  32 LogTagSet*  LogTagSet::_list      = NULL;
  33 size_t      LogTagSet::_ntagsets  = 0;
  34 
  35 // This constructor is called only during static initialization.
  36 // See the declaration in logTagSet.hpp for more information.
  37 LogTagSet::LogTagSet(LogTagType t0, LogTagType t1, LogTagType t2, LogTagType t3, LogTagType t4)
  38     : _next(_list) {
  39   _tag[0] = t0;
  40   _tag[1] = t1;
  41   _tag[2] = t2;
  42   _tag[3] = t3;
  43   _tag[4] = t4;
  44   for (_ntags = 0; _ntags < LogTag::MaxTags && _tag[_ntags] != LogTag::__NO_TAG; _ntags++) {
  45   }
  46   _list = this;
  47   _ntagsets++;


  58   LogDecorators new_decorators = decorator;
  59   for (LogOutputList::Iterator it = _output_list.iterator(); it != _output_list.end(); it++) {
  60     new_decorators.combine_with((*it)->decorators());
  61   }
  62   _decorators = new_decorators;
  63 }
  64 
  65 bool LogTagSet::has_output(const LogOutput* output) {
  66   for (LogOutputList::Iterator it = _output_list.iterator(); it != _output_list.end(); it++) {
  67     if (*it == output) {
  68       return true;
  69     }
  70   }
  71   return false;
  72 }
  73 
  74 void LogTagSet::log(LogLevelType level, const char* msg) {
  75   LogDecorations decorations(level, *this, _decorators);
  76   for (LogOutputList::Iterator it = _output_list.iterator(level); it != _output_list.end(); it++) {
  77     (*it)->write(decorations, msg);
  78   }
  79 }
  80 
  81 void LogTagSet::log(const LogMessageBuffer& msg) {
  82   LogDecorations decorations(LogLevel::Invalid, *this, _decorators);
  83   for (LogOutputList::Iterator it = _output_list.iterator(msg.least_detailed_level()); it != _output_list.end(); it++) {
  84     (*it)->write(msg.iterator(it.level(), decorations));
  85   }
  86 }
  87 
  88 int LogTagSet::label(char* buf, size_t len, const char* separator) const {
  89   int tot_written = 0;
  90   for (size_t i = 0; i < _ntags; i++) {
  91     int written = jio_snprintf(buf + tot_written, len - tot_written, "%s%s",
  92                                (i == 0 ? "" : separator),
  93                                LogTag::name(_tag[i]));
  94     if (written < 0) {
  95       return -1;
  96     }
  97     tot_written += written;
  98   }
  99   return tot_written;
 100 }
< prev index next >