util_logging.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright 2011-2014 Blender Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "util/util_logging.h"
  17. #include "util/util_math.h"
  18. #include "util/util_string.h"
  19. #include <stdio.h>
  20. #ifdef _MSC_VER
  21. # define snprintf _snprintf
  22. #endif
  23. CCL_NAMESPACE_BEGIN
  24. static bool is_verbosity_set()
  25. {
  26. #ifdef WITH_CYCLES_LOGGING
  27. using CYCLES_GFLAGS_NAMESPACE::GetCommandLineOption;
  28. std::string verbosity;
  29. if (!GetCommandLineOption("v", &verbosity)) {
  30. return false;
  31. }
  32. return verbosity != "0";
  33. #else
  34. return false;
  35. #endif
  36. }
  37. void util_logging_init(const char *argv0)
  38. {
  39. #ifdef WITH_CYCLES_LOGGING
  40. using CYCLES_GFLAGS_NAMESPACE::SetCommandLineOption;
  41. /* Make it so ERROR messages are always print into console. */
  42. char severity_fatal[32];
  43. snprintf(severity_fatal, sizeof(severity_fatal), "%d", google::GLOG_ERROR);
  44. google::InitGoogleLogging(argv0);
  45. SetCommandLineOption("logtostderr", "1");
  46. if (!is_verbosity_set()) {
  47. SetCommandLineOption("v", "0");
  48. }
  49. SetCommandLineOption("stderrthreshold", severity_fatal);
  50. SetCommandLineOption("minloglevel", severity_fatal);
  51. #else
  52. (void)argv0;
  53. #endif
  54. }
  55. void util_logging_start()
  56. {
  57. #ifdef WITH_CYCLES_LOGGING
  58. using CYCLES_GFLAGS_NAMESPACE::SetCommandLineOption;
  59. SetCommandLineOption("logtostderr", "1");
  60. if (!is_verbosity_set()) {
  61. SetCommandLineOption("v", "2");
  62. }
  63. SetCommandLineOption("stderrthreshold", "1");
  64. SetCommandLineOption("minloglevel", "0");
  65. #endif
  66. }
  67. void util_logging_verbosity_set(int verbosity)
  68. {
  69. #ifdef WITH_CYCLES_LOGGING
  70. using CYCLES_GFLAGS_NAMESPACE::SetCommandLineOption;
  71. char val[10];
  72. snprintf(val, sizeof(val), "%d", verbosity);
  73. SetCommandLineOption("v", val);
  74. #else
  75. (void)verbosity;
  76. #endif
  77. }
  78. std::ostream &operator<<(std::ostream &os, const int2 &value)
  79. {
  80. os << "(" << value.x << ", " << value.y << ")";
  81. return os;
  82. }
  83. std::ostream &operator<<(std::ostream &os, const float3 &value)
  84. {
  85. os << "(" << value.x << ", " << value.y << ", " << value.z << ")";
  86. return os;
  87. }
  88. CCL_NAMESPACE_END