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.
 
 
 
 
 

167 lines
4.1 KiB

  1. /*
  2. * Copyright (C) 2010-2011 Nick Schermer <nick@xfce.org>
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. #include <config.h>
  20. #endif
  21. #ifdef HAVE_STRING_H
  22. #include <string.h>
  23. #endif
  24. #include <glib.h>
  25. #include <common/panel-debug.h>
  26. #include <common/panel-private.h>
  27. static PanelDebugFlag panel_debug_flags = 0;
  28. /* additional debug levels */
  29. static const GDebugKey panel_debug_keys[] =
  30. {
  31. /* external plugin proxy modes */
  32. { "gdb", PANEL_DEBUG_GDB },
  33. { "valgrind", PANEL_DEBUG_VALGRIND },
  34. /* domains for debug messages in the code */
  35. { "application", PANEL_DEBUG_APPLICATION },
  36. { "applicationsmenu", PANEL_DEBUG_APPLICATIONSMENU },
  37. { "base-window", PANEL_DEBUG_BASE_WINDOW },
  38. { "display-layout", PANEL_DEBUG_DISPLAY_LAYOUT },
  39. { "external46", PANEL_DEBUG_EXTERNAL46 },
  40. { "external", PANEL_DEBUG_EXTERNAL },
  41. { "main", PANEL_DEBUG_MAIN },
  42. { "module-factory", PANEL_DEBUG_MODULE_FACTORY },
  43. { "module", PANEL_DEBUG_MODULE },
  44. { "positioning", PANEL_DEBUG_POSITIONING },
  45. { "struts", PANEL_DEBUG_STRUTS },
  46. { "systray", PANEL_DEBUG_SYSTRAY },
  47. { "tasklist", PANEL_DEBUG_TASKLIST }
  48. };
  49. static PanelDebugFlag
  50. panel_debug_init (void)
  51. {
  52. static volatile gsize inited__volatile = 0;
  53. const gchar *value;
  54. if (g_once_init_enter (&inited__volatile))
  55. {
  56. value = g_getenv ("PANEL_DEBUG");
  57. if (value != NULL && *value != '\0')
  58. {
  59. panel_debug_flags = g_parse_debug_string (value, panel_debug_keys,
  60. G_N_ELEMENTS (panel_debug_keys));
  61. /* always enable (unfiltered) debugging messages */
  62. PANEL_SET_FLAG (panel_debug_flags, PANEL_DEBUG_YES);
  63. /* unset gdb and valgrind in 'all' mode */
  64. if (g_ascii_strcasecmp (value, "all") == 0)
  65. PANEL_UNSET_FLAG (panel_debug_flags, PANEL_DEBUG_GDB | PANEL_DEBUG_VALGRIND);
  66. }
  67. g_once_init_leave (&inited__volatile, 1);
  68. }
  69. return panel_debug_flags;
  70. }
  71. static void
  72. panel_debug_print (PanelDebugFlag domain,
  73. const gchar *message,
  74. va_list args)
  75. {
  76. gchar *string;
  77. const gchar *domain_name = NULL;
  78. guint i;
  79. /* lookup domain name */
  80. for (i = 0; i < G_N_ELEMENTS (panel_debug_keys); i++)
  81. {
  82. if (panel_debug_keys[i].value == domain)
  83. {
  84. domain_name = panel_debug_keys[i].key;
  85. break;
  86. }
  87. }
  88. panel_assert (domain_name != NULL);
  89. string = g_strdup_vprintf (message, args);
  90. g_printerr (PACKAGE_NAME "(%s): %s\n", domain_name, string);
  91. g_free (string);
  92. }
  93. gboolean
  94. panel_debug_has_domain (PanelDebugFlag domain)
  95. {
  96. return PANEL_HAS_FLAG (panel_debug_flags, domain);
  97. }
  98. void
  99. panel_debug (PanelDebugFlag domain,
  100. const gchar *message,
  101. ...)
  102. {
  103. va_list args;
  104. panel_return_if_fail (domain > 0);
  105. panel_return_if_fail (message != NULL);
  106. /* leave when debug is disabled */
  107. if (panel_debug_init () == 0)
  108. return;
  109. va_start (args, message);
  110. panel_debug_print (domain, message, args);
  111. va_end (args);
  112. }
  113. void
  114. panel_debug_filtered (PanelDebugFlag domain,
  115. const gchar *message,
  116. ...)
  117. {
  118. va_list args;
  119. panel_return_if_fail (domain > 0);
  120. panel_return_if_fail (message != NULL);
  121. /* leave when the filter does not match */
  122. if (!PANEL_HAS_FLAG (panel_debug_init (), domain))
  123. return;
  124. va_start (args, message);
  125. panel_debug_print (domain, message, args);
  126. va_end (args);
  127. }