HierarchyMaintainer.cpp
Go to the documentation of this file.
1 /*
2  * HierarchyMaintainer.cpp
3  *
4  * Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
5  * Copyright 2000, Bastiaan Bakker. All rights reserved.
6  *
7  * See the COPYING file for the terms of usage and distribution.
8  */
9 
10 #include "PortabilityImpl.hh"
11 
12 #ifdef LOG4CPP_HAVE_IO_H
13 # include <io.h>
14 #endif
15 #ifdef LOG4CPP_HAVE_UNISTD_H
16 # include <unistd.h>
17 #endif
18 
19 #include <cstdio>
20 #include <cassert>
22 #include <log4cpp/FileAppender.hh>
23 
24 namespace log4cpp {
25 
27 
29  static HierarchyMaintainer defaultMaintainer;
30 
31  return defaultMaintainer;
32  }
33 
35  }
36 
38  shutdown();
40  }
41 
44  return _getExistingInstance(name);
45  }
46 
48  Category* result = NULL;
49 
50  CategoryMap::iterator i = _categoryMap.find(name);
51  if (_categoryMap.end() != i) {
52  result = (*i).second;
53  }
54 
55  return result;
56  }
57 
58  Category& HierarchyMaintainer::getInstance(const std::string& name) {
60  return _getInstance(name);
61  }
62 
63  /* assume lock is held */
64  Category& HierarchyMaintainer::_getInstance(const std::string& name) {
65  Category* result;
66  result = _getExistingInstance(name);
67 
68  if (NULL == result) {
69  if (name == "") {
70  result = make_category(name, NULL, Priority::INFO);
71  } else {
72  std::string parentName;
73  size_t dotIndex = name.find_last_of('.');
74  if (name.length() <= dotIndex) {
75  parentName = "";
76  } else {
77  parentName = name.substr(0, dotIndex);
78  }
79  Category& parent = _getInstance(parentName);
80  result = make_category(name, &parent, Priority::NOTSET);
81  }
82  _categoryMap[name] = result;
83  }
84  return *result;
85  }
86 
87  std::vector<Category*>* HierarchyMaintainer::getCurrentCategories() const {
88  std::vector<Category*>* categories = new std::vector<Category*>;
89 
91  {
92  for(CategoryMap::const_iterator i = _categoryMap.begin(); i != _categoryMap.end(); i++) {
93  categories->push_back((*i).second);
94  }
95  }
96 
97  return categories;
98  }
99 
102  {
103  for(CategoryMap::const_iterator i = _categoryMap.begin(); i != _categoryMap.end(); i++) {
104  ((*i).second)->removeAllAppenders();
105  }
106  }
107 
108  try
109  {
110  for(handlers_t::const_iterator i = handlers_.begin(), last = handlers_.end(); i != last; ++i)
111  (**i)();
112  }
113  catch(...)
114  {
115  }
116 
117  }
118 
120  {
121  handlers_.push_back(handler);
122  }
123 
126  {
127  for(CategoryMap::const_iterator i = _categoryMap.begin(); i != _categoryMap.end(); i++) {
128  delete ((*i).second);
129  }
130  _categoryMap.erase(_categoryMap.begin(), _categoryMap.end());
131  }
132  }
133 
135  {
136  assert(0 != creator_function);
137  _creator_function = creator_function;
138  }
139 
141  Category* parent,
142  Priority::Value priority)
143  {
144  if (_creator_function)
145  {
146  return (*_creator_function)(name, parent, priority);
147  }
148  else
149  {
150  return new Category(name, parent, priority);
151  }
152  }
153 }
virtual Category & getInstance(const std::string &name)
static void set_category_factory(creator_function_t creator_function)
Category *(* creator_function_t)(const std::string &name, log4cpp::Category *parent, log4cpp::Priority::Value priority)
virtual Category * getExistingInstance(const std::string &name)
virtual Category & _getInstance(const std::string &name)
static creator_function_t _creator_function
static Category * make_category(const std::string &name, log4cpp::Category *parent, log4cpp::Priority::Value priority)
static HierarchyMaintainer & getDefaultMaintainer()
virtual std::vector< Category * > * getCurrentCategories() const
virtual Category * _getExistingInstance(const std::string &name)
class LOG4CPP_EXPORT Category
void register_shutdown_handler(shutdown_fun_ptr handler)


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Jun 23 2019 19:10:00