1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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 #ifndef SHARE_VM_LOGGING_LOGTAGLEVELEXPRESSION_HPP
  25 #define SHARE_VM_LOGGING_LOGTAGLEVELEXPRESSION_HPP
  26 
  27 #include "logging/logLevel.hpp"
  28 #include "logging/logTag.hpp"
  29 #include "memory/allocation.hpp"
  30 #include "utilities/debug.hpp"
  31 #include "utilities/globalDefinitions.hpp"
  32 
  33 class LogTagSet;
  34 
  35 // Class used to temporary encode a 'what'-expression during log configuration.
  36 // Consists of a combination of tags and levels, e.g. "tag1+tag2=level1,tag3*=level2".
  37 class LogTagLevelExpression : public StackObj {
  38  private:
  39   static const size_t MaxCombinations = 32;
  40   static const char* DefaultExpressionString;
  41 
  42   size_t        _ntags, _ncombinations;
  43   LogTagType    _tags[MaxCombinations][LogTag::MaxTags];
  44   LogLevelType  _level[MaxCombinations];
  45   bool          _allow_other_tags[MaxCombinations];
  46   char*         _string;
  47 
  48   void new_combination() {
  49     _ncombinations++;
  50     _ntags = 0;
  51   }
  52 
  53   void add_tag(LogTagType tag) {
  54     assert(_ntags < LogTag::MaxTags, "Can't have more tags than MaxTags!");
  55     _tags[_ncombinations][_ntags++] = tag;
  56   }
  57 
  58   void set_level(LogLevelType level) {
  59     _level[_ncombinations] = level;
  60   }
  61 
  62   void set_allow_other_tags() {
  63     _allow_other_tags[_ncombinations] = true;
  64   }
  65 
  66   void clear();
  67 
  68  public:
  69   LogTagLevelExpression() : _ntags(0), _ncombinations(0), _string(NULL) {
  70   }
  71 
  72   const char* to_string() const {
  73     return _string;
  74   }
  75 
  76   ~LogTagLevelExpression();
  77   bool parse(const char* str, outputStream* errstream = NULL);
  78   LogLevelType level_for(const LogTagSet& ts) const;
  79 };
  80 
  81 #endif // SHARE_VM_LOGGING_LOGTAGLEVELEXPRESSION_HPP