glib-2.66.7-skip_warnings-1.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. Submitted By: Bruce dubbs <bdubbs@linuxfromscratch.org>
  2. Date: 2017-10-15
  3. Initial Package Version: 2.54.0
  4. Upstream Status: Not submitted
  5. Origin: Self
  6. Description: Adds a capabiility to skip printing warning messages using
  7. an environment variable: GLIB_LOG_LEVEL. The value
  8. of the variable is a digit that correponds to:
  9. 1 Alert
  10. 2 Critical
  11. 3 Error
  12. 4 Warning
  13. 5 Notice
  14. For instance GLIB_LOG_LEVEL=4 will skip output of Waring and
  15. Notice messages (and Info/Debug messages if they are turned on).
  16. --- glib-2.54.0/glib/gmessages.c 2017-08-19 08:39:20.000000000 -0500
  17. +++ glib-2.54.0-new/glib/gmessages.c 2017-10-15 14:45:52.004885278 -0500
  18. @@ -523,6 +523,35 @@
  19. /* --- functions --- */
  20. +/* skip_message
  21. + *
  22. + * This internal function queries an optional environment variable,
  23. + * GLIB_LOG_LEVEL and converts it to a value consistent
  24. + * with the type GLogLevelFlags. If the value is equal to
  25. + * or greater than the integer equivalent of the log_level.
  26. + * then the function returns a boolean that indicates that
  27. + * loging the output should be skipped.
  28. + */
  29. +
  30. +static gboolean skip_message( GLogLevelFlags log_level);
  31. +
  32. +static gboolean skip_message( GLogLevelFlags log_level)
  33. +{
  34. + char* user_log_level;
  35. + int user_log_int;
  36. + gboolean skip = FALSE;
  37. +
  38. + user_log_level = getenv( "GLIB_LOG_LEVEL" );
  39. +
  40. + user_log_int = ( user_log_level != NULL ) ? atoi( user_log_level ) : 0;
  41. + user_log_int = ( user_log_int != 0 ) ? 1 << user_log_int : 0;
  42. +
  43. + if ( user_log_int >= log_level ) skip = TRUE;
  44. +
  45. + return skip;
  46. +}
  47. +
  48. +
  49. static void _g_log_abort (gboolean breakpoint);
  50. static void
  51. @@ -2496,6 +2525,9 @@
  52. g_return_val_if_fail (fields != NULL, G_LOG_WRITER_UNHANDLED);
  53. g_return_val_if_fail (n_fields > 0, G_LOG_WRITER_UNHANDLED);
  54. + /* If the user does not want this message level, just return */
  55. + if ( skip_message( log_level) ) return G_LOG_WRITER_HANDLED;
  56. +
  57. stream = log_level_to_file (log_level);
  58. if (!stream || fileno (stream) < 0)
  59. return G_LOG_WRITER_UNHANDLED;
  60. @@ -2640,6 +2672,9 @@
  61. FILE *stream;
  62. gsize i;
  63. + /* If the user does not want this message level, just return */
  64. + if ( skip_message( log_level) ) return G_LOG_WRITER_HANDLED;
  65. +
  66. /* we cannot call _any_ GLib functions in this fallback handler,
  67. * which is why we skip UTF-8 conversion, etc.
  68. * since we either recursed or ran out of memory, we're in a pretty