Blender  V2.93
util_logging.cpp
Go to the documentation of this file.
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 
17 #include "util/util_logging.h"
18 
19 #include "util/util_math.h"
20 #include "util/util_string.h"
21 
22 #include <stdio.h>
23 #ifdef _MSC_VER
24 # define snprintf _snprintf
25 #endif
26 
28 
29 static bool is_verbosity_set()
30 {
31 #ifdef WITH_CYCLES_LOGGING
32  using CYCLES_GFLAGS_NAMESPACE::GetCommandLineOption;
33 
34  std::string verbosity;
35  if (!GetCommandLineOption("v", &verbosity)) {
36  return false;
37  }
38  return verbosity != "0";
39 #else
40  return false;
41 #endif
42 }
43 
44 void util_logging_init(const char *argv0)
45 {
46 #ifdef WITH_CYCLES_LOGGING
47  using CYCLES_GFLAGS_NAMESPACE::SetCommandLineOption;
48 
49  google::InitGoogleLogging(argv0);
50  SetCommandLineOption("logtostderr", "1");
51  if (!is_verbosity_set()) {
52  SetCommandLineOption("v", "0");
53  }
54  SetCommandLineOption("stderrthreshold", "0");
55  SetCommandLineOption("minloglevel", "0");
56 #else
57  (void)argv0;
58 #endif
59 }
60 
62 {
63 #ifdef WITH_CYCLES_LOGGING
64  using CYCLES_GFLAGS_NAMESPACE::SetCommandLineOption;
65  SetCommandLineOption("logtostderr", "1");
66  if (!is_verbosity_set()) {
67  SetCommandLineOption("v", "2");
68  }
69  SetCommandLineOption("stderrthreshold", "0");
70  SetCommandLineOption("minloglevel", "0");
71 #endif
72 }
73 
74 void util_logging_verbosity_set(int verbosity)
75 {
76 #ifdef WITH_CYCLES_LOGGING
77  using CYCLES_GFLAGS_NAMESPACE::SetCommandLineOption;
78  char val[10];
79  snprintf(val, sizeof(val), "%d", verbosity);
80  SetCommandLineOption("v", val);
81 #else
82  (void)verbosity;
83 #endif
84 }
85 
86 std::ostream &operator<<(std::ostream &os, const int2 &value)
87 {
88  os << "(" << value.x << ", " << value.y << ")";
89  return os;
90 }
91 
92 std::ostream &operator<<(std::ostream &os, const float3 &value)
93 {
94  os << "(" << value.x << ", " << value.y << ", " << value.z << ")";
95  return os;
96 }
97 
#define snprintf
Definition: BLI_winstuff.h:69
#define CCL_NAMESPACE_END
float z
Definition: sky_float3.h:35
float y
Definition: sky_float3.h:35
float x
Definition: sky_float3.h:35
void util_logging_init(const char *argv0)
std::ostream & operator<<(std::ostream &os, const int2 &value)
static CCL_NAMESPACE_BEGIN bool is_verbosity_set()
void util_logging_verbosity_set(int verbosity)
void util_logging_start()