You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.1 KiB

  1. // -*- C++ -*-
  2. // Module: Log4CPLUS
  3. // File: hierarchylocker.h
  4. // Created: 8/2003
  5. // Author: Tad E. Smith
  6. //
  7. //
  8. // Copyright 2003-2013 Tad E. Smith
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the "License");
  11. // you may not use this file except in compliance with the License.
  12. // You may obtain a copy of the License at
  13. //
  14. // http://www.apache.org/licenses/LICENSE-2.0
  15. //
  16. // Unless required by applicable law or agreed to in writing, software
  17. // distributed under the License is distributed on an "AS IS" BASIS,
  18. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. // See the License for the specific language governing permissions and
  20. // limitations under the License.
  21. /** @file */
  22. #ifndef LOG4CPLUS_HIERARCHY_LOCKER_HEADER_
  23. #define LOG4CPLUS_HIERARCHY_LOCKER_HEADER_
  24. #include <log4cplus/config.hxx>
  25. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  26. #pragma once
  27. #endif
  28. #include <log4cplus/tstring.h>
  29. #include <log4cplus/appender.h>
  30. #include <log4cplus/logger.h>
  31. namespace log4cplus
  32. {
  33. class Hierarchy;
  34. /**
  35. * This is used to lock a Hierarchy. The dtor unlocks the Hierarchy.
  36. */
  37. class LOG4CPLUS_EXPORT HierarchyLocker {
  38. public:
  39. // ctor & dtor
  40. HierarchyLocker(Hierarchy& h);
  41. ~HierarchyLocker();
  42. /**
  43. * Calls the <code>resetConfiguration()</code> method on the locked Hierarchy.
  44. */
  45. void resetConfiguration();
  46. /**
  47. * Calls the <code>getInstance()</code> method on the locked Hierarchy.
  48. */
  49. Logger getInstance(const log4cplus::tstring& name);
  50. /**
  51. * Calls the <code>getInstance()</code> method on the locked Hierarchy.
  52. */
  53. Logger getInstance(const log4cplus::tstring& name, spi::LoggerFactory& factory);
  54. void addAppender(Logger &logger, log4cplus::SharedAppenderPtr& appender);
  55. private:
  56. // Data
  57. Hierarchy& h;
  58. log4cplus::thread::MutexGuard hierarchyLocker;
  59. LoggerList loggerList;
  60. };
  61. } // end namespace log4cplus
  62. #endif // LOG4CPLUS_HIERARCHY_LOCKER_HEADER_