logging.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * Logging functions copied from main.cc to avoid link errors for plugins
  21. */
  22. #include "thrift/logging.h"
  23. #include "thrift/globals.h"
  24. #include <cstdarg>
  25. #include <cstdio>
  26. #include <cstdlib>
  27. // TODO: make plugins accept log options from main compiler
  28. int g_debug = 0;
  29. int g_warn = 1;
  30. int g_verbose = 0;
  31. void pdebug(const char* fmt, ...) {
  32. if (g_debug == 0) {
  33. return;
  34. }
  35. va_list args;
  36. // printf("[PARSE:%d] ", yylineno);
  37. va_start(args, fmt);
  38. vprintf(fmt, args);
  39. va_end(args);
  40. printf("\n");
  41. }
  42. void pverbose(const char* fmt, ...) {
  43. if (g_verbose == 0) {
  44. return;
  45. }
  46. va_list args;
  47. va_start(args, fmt);
  48. vprintf(fmt, args);
  49. va_end(args);
  50. }
  51. void pwarning(int level, const char* fmt, ...) {
  52. if (g_warn < level) {
  53. return;
  54. }
  55. va_list args;
  56. // printf("[WARNING:%s:%d] ", g_curpath.c_str(), yylineno);
  57. va_start(args, fmt);
  58. vprintf(fmt, args);
  59. va_end(args);
  60. printf("\n");
  61. }
  62. void failure(const char* fmt, ...) {
  63. va_list args;
  64. // fprintf(stderr, "[FAILURE:%s:%d] ", g_curpath.c_str(), yylineno);
  65. va_start(args, fmt);
  66. vfprintf(stderr, fmt, args);
  67. va_end(args);
  68. printf("\n");
  69. exit(1);
  70. }