logger_name.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <string>
  15. #include "log/logger_name.h"
  16. namespace isc {
  17. namespace log {
  18. namespace {
  19. // Obtain the root logger name in a way that is safe for statically-initialized
  20. // objects.
  21. std::string&
  22. getRootLoggerNameInternal() {
  23. static std::string root_name;
  24. return (root_name);
  25. }
  26. } // Anonymous namespace
  27. void
  28. setRootLoggerName(const std::string& name) {
  29. getRootLoggerNameInternal() = name;
  30. }
  31. const std::string& getRootLoggerName() {
  32. return (getRootLoggerNameInternal());
  33. }
  34. std::string expandLoggerName(const std::string& name) {
  35. // Are we the root logger, or does the logger name start with
  36. // the string "<root_logger_name>.". If so, use a logger
  37. // whose name is the one given.
  38. if ((name == getRootLoggerName()) ||
  39. (name.find(getRootLoggerName() + std::string(".")) == 0)) {
  40. return (name);
  41. }
  42. // Anything else is assumed to be a sub-logger of the root logger.
  43. return (getRootLoggerName() + "." + name);
  44. }
  45. } // namespace log
  46. } // namespace isc