diff --git a/intern/cycles/app/cycles_standalone.cpp b/intern/cycles/app/cycles_standalone.cpp index 69518684103..510ed7e92f9 100644 --- a/intern/cycles/app/cycles_standalone.cpp +++ b/intern/cycles/app/cycles_standalone.cpp @@ -539,7 +539,7 @@ using namespace ccl; int main(const int argc, const char **argv) { - log_init(argv[0]); + log_init(nullptr); path_init(); options_parse(argc, argv); diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp index f4aa8e759cb..68bc744668f 100644 --- a/intern/cycles/app/cycles_xml.cpp +++ b/intern/cycles/app/cycles_xml.cpp @@ -22,8 +22,10 @@ #include "scene/shader_graph.h" #include "scene/shader_nodes.h" +#include "util/log.h" #include "util/path.h" #include "util/projection.h" +#include "util/string.h" #include "util/transform.h" #include "util/xml.h" @@ -261,14 +263,12 @@ static void xml_read_shader_graph(XMLReadState &state, Shader *shader, const xml } if (!output) { - fprintf(stderr, - "Unknown output socket name \"%s\" on \"%s\".\n", - from_node_name.c_str(), - from_socket_name.c_str()); + LOG(ERROR) << "Unknown output socket name \"" << from_node_name << "\" on \"" + << from_socket_name << "\"."; } } else { - fprintf(stderr, "Unknown shader node name \"%s\".\n", from_node_name.c_str()); + LOG(ERROR) << "Unknown shader node name \"" << from_node_name << "\""; } if (graph_reader.node_map.find(to_node_name) != graph_reader.node_map.end()) { @@ -281,14 +281,12 @@ static void xml_read_shader_graph(XMLReadState &state, Shader *shader, const xml } if (!input) { - fprintf(stderr, - "Unknown input socket name \"%s\" on \"%s\".\n", - to_socket_name.c_str(), - to_node_name.c_str()); + LOG(ERROR) << "Unknown input socket name \"" << to_socket_name << "\" on \"" + << to_node_name << "\""; } } else { - fprintf(stderr, "Unknown shader node name \"%s\".\n", to_node_name.c_str()); + LOG(ERROR) << "Unknown shader node name \"" << to_node_name << "\""; } /* connect */ @@ -297,7 +295,7 @@ static void xml_read_shader_graph(XMLReadState &state, Shader *shader, const xml } } else { - fprintf(stderr, "Invalid from or to value for connect node.\n"); + LOG(ERROR) << "Invalid from or to value for connect node."; } continue; @@ -320,17 +318,17 @@ static void xml_read_shader_graph(XMLReadState &state, Shader *shader, const xml snode = OSLShaderManager::osl_node(graph.get(), state.scene, filepath, ""); if (!snode) { - fprintf(stderr, "Failed to create OSL node from \"%s\".\n", filepath.c_str()); + LOG(ERROR) << "Failed to create OSL node from \"" << filepath << "\""; continue; } } else { - fprintf(stderr, "OSL node missing \"src\" attribute.\n"); + LOG(ERROR) << "OSL node missing \"src\" attribute."; continue; } } else { - fprintf(stderr, "OSL node without using --shadingsys osl.\n"); + LOG(ERROR) << "OSL node without using --shadingsys osl."; continue; } } @@ -345,15 +343,16 @@ static void xml_read_shader_graph(XMLReadState &state, Shader *shader, const xml const NodeType *node_type = NodeType::find(node_name); if (!node_type) { - fprintf(stderr, "Unknown shader node \"%s\".\n", node.name()); + LOG(ERROR) << "Unknown shader node \"" << node.name() << "\""; continue; } if (node_type->type != NodeType::SHADER) { - fprintf(stderr, "Node type \"%s\" is not a shader node.\n", node_type->name.c_str()); + LOG(ERROR) << "Node type \"" << node_type->name << "\" is not a shader node"; continue; } if (node_type->create == nullptr) { - fprintf(stderr, "Can't create abstract node type \"%s\".\n", node_type->name.c_str()); + LOG(ERROR) << "Can't create abstract node type \"" + << "\""; continue; } @@ -698,7 +697,7 @@ static void xml_read_state(XMLReadState &state, const xml_node node) } if (!found) { - fprintf(stderr, "Unknown shader \"%s\".\n", shadername.c_str()); + LOG(ERROR) << "Unknown shader \"" << shadername << "\""; } } @@ -717,7 +716,7 @@ static void xml_read_state(XMLReadState &state, const xml_node node) } if (!found) { - fprintf(stderr, "Unknown object \"%s\".\n", objectname.c_str()); + LOG(ERROR) << "Unknown object \"" << objectname << "\""; } } @@ -808,7 +807,7 @@ static void xml_read_scene(XMLReadState &state, const xml_node scene_node) } #endif else { - fprintf(stderr, "Unknown node \"%s\".\n", node.name()); + LOG(ERROR) << "Unknown node \"" << node.name() << "\""; } } } @@ -832,7 +831,7 @@ static void xml_read_include(XMLReadState &state, const string &src) xml_read_scene(substate, cycles); } else { - fprintf(stderr, "%s read error: %s\n", src.c_str(), parse_result.description()); + LOG(ERROR) << "\"" << src << "\" read error: " << parse_result.description(); exit(EXIT_FAILURE); } } diff --git a/intern/cycles/app/opengl/window.cpp b/intern/cycles/app/opengl/window.cpp index ebe034aa6c7..672978f39f3 100644 --- a/intern/cycles/app/opengl/window.cpp +++ b/intern/cycles/app/opengl/window.cpp @@ -7,6 +7,7 @@ #include "app/opengl/window.h" +#include "util/log.h" #include "util/string.h" #include "util/thread.h" #include "util/version.h" @@ -66,7 +67,7 @@ static void window_display_text(int /*x*/, int /*y*/, const char *text) static string last_text; if (text != last_text) { - printf("%s\n", text); + LOG(INFO_IMPORTANT) << text; last_text = text; } #endif @@ -291,7 +292,7 @@ void window_main_loop(const char *title, height, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); if (V.window == nullptr) { - fprintf(stderr, "Failed to create window: %s\n", SDL_GetError()); + LOG(ERROR) << "Failed to create window: " << SDL_GetError(); return; } diff --git a/intern/cycles/blender/logging.cpp b/intern/cycles/blender/logging.cpp index ca92da52412..5aa7ea47e4e 100644 --- a/intern/cycles/blender/logging.cpp +++ b/intern/cycles/blender/logging.cpp @@ -29,6 +29,7 @@ void CCL_log_init() CLG_log_str(log_type, CLG_SEVERITY_WARN, file_line, func, msg); return; case ccl::INFO: + case ccl::INFO_IMPORTANT: case ccl::WORK: case ccl::STATS: case ccl::DEBUG: diff --git a/intern/cycles/blender/python.cpp b/intern/cycles/blender/python.cpp index d4a8ade302a..406fa1694d6 100644 --- a/intern/cycles/blender/python.cpp +++ b/intern/cycles/blender/python.cpp @@ -17,7 +17,7 @@ #include "util/debug.h" #include "util/guiding.h" -#include "util/md5.h" +#include "util/log.h" #include "util/openimagedenoise.h" #include "util/path.h" #include "util/string.h" @@ -727,7 +727,7 @@ static PyObject *set_device_override_func(PyObject * /*self*/, PyObject *arg) BlenderSession::device_override = DEVICE_MASK_ONEAPI; } else { - fprintf(stderr, "\nError: %s is not a valid Cycles device.\n", override.c_str()); + LOG(ERROR) << override << " is not a valid Cycles device."; Py_RETURN_FALSE; } diff --git a/intern/cycles/blender/volume.cpp b/intern/cycles/blender/volume.cpp index 4c50ddef792..43e61e6d46d 100644 --- a/intern/cycles/blender/volume.cpp +++ b/intern/cycles/blender/volume.cpp @@ -10,6 +10,8 @@ #include "blender/sync.h" #include "blender/util.h" +#include "util/log.h" + #include "BKE_volume_grid.hh" CCL_NAMESPACE_BEGIN @@ -140,16 +142,15 @@ class BlenderSmokeLoader : public ImageLoader { } } else { - fprintf(stderr, - "Cycles error: unknown volume attribute %s, skipping\n", - Attribute::standard_name(attribute)); + LOG(ERROR) << "Unknown volume attribute " << Attribute::standard_name(attribute) + << "skipping "; fpixels[0] = 0.0f; return false; } #else (void)pixels; #endif - fprintf(stderr, "Cycles error: unexpected smoke volume resolution, skipping\n"); + LOG(ERROR) << "Unexpected smoke volume resolution, skipping"; return false; } diff --git a/intern/cycles/device/cuda/device.cpp b/intern/cycles/device/cuda/device.cpp index 062fcd8f04c..96978638472 100644 --- a/intern/cycles/device/cuda/device.cpp +++ b/intern/cycles/device/cuda/device.cpp @@ -109,7 +109,7 @@ void device_cuda_info(vector &devices) CUresult result = device_cuda_safe_init(); if (result != CUDA_SUCCESS) { if (result != CUDA_ERROR_NO_DEVICE) { - fprintf(stderr, "CUDA cuInit: %s\n", cuewErrorString(result)); + LOG(ERROR) << "CUDA cuInit: " << cuewErrorString(result); } return; } @@ -117,7 +117,7 @@ void device_cuda_info(vector &devices) int count = 0; result = cuDeviceGetCount(&count); if (result != CUDA_SUCCESS) { - fprintf(stderr, "CUDA cuDeviceGetCount: %s\n", cuewErrorString(result)); + LOG(ERROR) << "CUDA cuDeviceGetCount: " << cuewErrorString(result); return; } @@ -128,7 +128,7 @@ void device_cuda_info(vector &devices) result = cuDeviceGetName(name, 256, num); if (result != CUDA_SUCCESS) { - fprintf(stderr, "CUDA cuDeviceGetName: %s\n", cuewErrorString(result)); + LOG(ERROR) << "CUDA cuDeviceGetName: " << cuewErrorString(result); continue; } diff --git a/intern/cycles/device/cuda/device_impl.cpp b/intern/cycles/device/cuda/device_impl.cpp index d96e5b62e0f..1c498143120 100644 --- a/intern/cycles/device/cuda/device_impl.cpp +++ b/intern/cycles/device/cuda/device_impl.cpp @@ -8,6 +8,7 @@ # include # include # include +# include # include "device/cuda/device_impl.h" @@ -339,19 +340,13 @@ string CUDADevice::compile_kernel(const string &common_cflags, const int nvcc_cuda_version = cuewCompilerVersion(); LOG(INFO) << "Found nvcc " << nvcc << ", CUDA version " << nvcc_cuda_version << "."; if (nvcc_cuda_version < 101) { - printf( - "Unsupported CUDA version %d.%d detected, " - "you need CUDA 10.1 or newer.\n", - nvcc_cuda_version / 10, - nvcc_cuda_version % 10); + LOG(WARNING) << "Unsupported CUDA version " << nvcc_cuda_version / 10 << "." + << nvcc_cuda_version % 10 << ", you need CUDA 10.1 or newer"; return string(); } if (!(nvcc_cuda_version >= 102 && nvcc_cuda_version < 130)) { - printf( - "CUDA version %d.%d detected, build may succeed but only " - "CUDA 10.1 to 12 are officially supported.\n", - nvcc_cuda_version / 10, - nvcc_cuda_version % 10); + LOG(WARNING) << "CUDA version " << nvcc_cuda_version / 10 << "." << nvcc_cuda_version % 10 + << "CUDA 10.1 to 12 are officially supported."; } double starttime = time_dt(); @@ -376,9 +371,9 @@ string CUDADevice::compile_kernel(const string &common_cflags, cubin.c_str(), common_cflags.c_str()); - printf("Compiling %sCUDA kernel ...\n%s\n", - (use_adaptive_compilation()) ? "adaptive " : "", - command.c_str()); + LOG(INFO_IMPORTANT) << "Compiling " << ((use_adaptive_compilation()) ? "adaptive " : "") + << "CUDA kernel ..."; + LOG(INFO_IMPORTANT) << command; # ifdef _WIN32 command = "call " + command; @@ -398,7 +393,8 @@ string CUDADevice::compile_kernel(const string &common_cflags, return string(); } - printf("Kernel compilation finished in %.2lfs.\n", time_dt() - starttime); + LOG(INFO_IMPORTANT) << "Kernel compilation finished in " << std::fixed << std::setprecision(2) + << time_dt() - starttime << "s"; return cubin; } diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp index 59476c9eb66..281e5fb86a6 100644 --- a/intern/cycles/device/device.cpp +++ b/intern/cycles/device/device.cpp @@ -49,6 +49,15 @@ uint Device::devices_initialized_mask = 0; Device::~Device() noexcept(false) = default; +void Device::set_error(const string &error) +{ + if (!have_error()) { + error_msg = error; + } + LOG(ERROR) << error; + fflush(stderr); +} + void Device::build_bvh(BVH *bvh, Progress &progress, bool refit) { assert(bvh->params.bvh_layout == BVH_LAYOUT_BVH2); diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h index b28ef4565e3..1f3de252314 100644 --- a/intern/cycles/device/device.h +++ b/intern/cycles/device/device.h @@ -158,14 +158,7 @@ class Device { { return !error_message().empty(); } - virtual void set_error(const string &error) - { - if (!have_error()) { - error_msg = error; - } - fprintf(stderr, "%s\n", error.c_str()); - fflush(stderr); - } + virtual void set_error(const string &error); virtual BVHLayoutMask get_bvh_layout_mask(const uint kernel_features) const = 0; /* statistics */ diff --git a/intern/cycles/device/hip/device.cpp b/intern/cycles/device/hip/device.cpp index 2d023a3d1b9..da5b50746ac 100644 --- a/intern/cycles/device/hip/device.cpp +++ b/intern/cycles/device/hip/device.cpp @@ -129,7 +129,7 @@ void device_hip_info(vector &devices) hipError_t result = device_hip_safe_init(); if (result != hipSuccess) { if (result != hipErrorNoDevice) { - fprintf(stderr, "HIP hipInit: %s\n", hipewErrorString(result)); + LOG(ERROR) << "HIP hipInit: " << hipewErrorString(result); } return; } @@ -137,7 +137,7 @@ void device_hip_info(vector &devices) int count = 0; result = hipGetDeviceCount(&count); if (result != hipSuccess) { - fprintf(stderr, "HIP hipGetDeviceCount: %s\n", hipewErrorString(result)); + LOG(ERROR) << "HIP hipGetDeviceCount: " << hipewErrorString(result); return; } @@ -154,7 +154,7 @@ void device_hip_info(vector &devices) result = hipDeviceGetName(name, 256, num); if (result != hipSuccess) { - fprintf(stderr, "HIP :hipDeviceGetName: %s\n", hipewErrorString(result)); + LOG(ERROR) << "HIP hipDeviceGetName: " << hipewErrorString(result); continue; } diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index 15fe203b853..f51ab81d305 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -7,6 +7,7 @@ # include # include # include +# include # include "device/hip/device_impl.h" @@ -345,9 +346,8 @@ string HIPDevice::compile_kernel(const uint kernel_features, const char *name, c fatbin.c_str(), common_cflags.c_str()); - printf("Compiling %sHIP kernel ...\n%s\n", - (use_adaptive_compilation()) ? "adaptive " : "", - command.c_str()); + LOG(INFO_IMPORTANT) << "Compiling " << ((use_adaptive_compilation()) ? "adaptive " : "") + << "HIP kernel ..."; # ifdef _WIN32 command = "call " + command; @@ -367,7 +367,8 @@ string HIPDevice::compile_kernel(const uint kernel_features, const char *name, c return string(); } - printf("Kernel compilation finished in %.2lfs.\n", time_dt() - starttime); + LOG(INFO_IMPORTANT) << "Kernel compilation finished in " << std::fixed << std::setprecision(2) + << time_dt() - starttime << "s"; return fatbin; } diff --git a/intern/cycles/device/hiprt/device_impl.cpp b/intern/cycles/device/hiprt/device_impl.cpp index 015f6e4335f..2d29d153dfb 100644 --- a/intern/cycles/device/hiprt/device_impl.cpp +++ b/intern/cycles/device/hiprt/device_impl.cpp @@ -4,8 +4,10 @@ #ifdef WITH_HIPRT -# include "device/hiprt/device_impl.h" +# include + # include "device/hip/util.h" +# include "device/hiprt/device_impl.h" # include "kernel/device/hiprt/globals.h" # include "util/log.h" @@ -152,9 +154,9 @@ string HIPRTDevice::compile_kernel(const uint kernel_features, const char *name, if (!use_adaptive_compilation()) { const string fatbin = path_get(string_printf("lib/%s_rt_%s.hipfb.zst", name, arch.c_str())); - VLOG(1) << "Testing for pre-compiled kernel " << fatbin << "."; + LOG(INFO) << "Testing for pre-compiled kernel " << fatbin << "."; if (path_exists(fatbin)) { - VLOG(1) << "Using precompiled kernel."; + LOG(INFO) << "Using precompiled kernel."; return fatbin; } } @@ -171,9 +173,9 @@ string HIPRTDevice::compile_kernel(const uint kernel_features, const char *name, const string fatbin = path_cache_get(path_join("kernels", fatbin_file)); const string hiprt_include_path = path_join(source_path, "kernel/device/hiprt"); - VLOG(1) << "Testing for locally compiled kernel " << fatbin << "."; + LOG(INFO) << "Testing for locally compiled kernel " << fatbin << "."; if (path_exists(fatbin)) { - VLOG(1) << "Using locally compiled kernel."; + LOG(INFO) << "Using locally compiled kernel."; return fatbin; } @@ -208,11 +210,8 @@ string HIPRTDevice::compile_kernel(const uint kernel_features, const char *name, const int hipcc_hip_version = hipewCompilerVersion(); LOG(INFO) << "Found hipcc " << hipcc << ", HIP version " << hipcc_hip_version << "."; if (hipcc_hip_version < 40) { - printf( - "Unsupported HIP version %d.%d detected, " - "you need HIP 4.0 or newer.\n", - hipcc_hip_version / 10, - hipcc_hip_version % 10); + LOG(WARNING) << "Unsupported HIP version " << hipcc_hip_version / 10 << "." + << hipcc_hip_version % 10 << ", you need HIP 4.0 or newer.\n"; return string(); } @@ -235,7 +234,7 @@ string HIPRTDevice::compile_kernel(const uint kernel_features, const char *name, options.append(" -D WITH_NANOVDB"); # endif - printf("Compiling %s and caching to %s", source_path.c_str(), fatbin.c_str()); + LOG(INFO_IMPORTANT) << "Compiling " << source_path << " and caching to " << fatbin; double starttime = time_dt(); @@ -258,7 +257,8 @@ string HIPRTDevice::compile_kernel(const uint kernel_features, const char *name, return string(); } - printf("Kernel compilation finished in %.2lfs.\n", time_dt() - starttime); + LOG(INFO_IMPORTANT) << "Kernel compilation finished in " << std::fixed << std::setprecision(2) + << time_dt() - starttime << "s"; return fatbin; } @@ -267,7 +267,7 @@ bool HIPRTDevice::load_kernels(const uint kernel_features) { if (hipModule) { if (use_adaptive_compilation()) { - VLOG(1) << "Skipping HIP kernel reload for adaptive compilation, not currently supported."; + LOG(INFO) << "Skipping HIP kernel reload for adaptive compilation, not currently supported."; } return true; } diff --git a/intern/cycles/device/queue.cpp b/intern/cycles/device/queue.cpp index 10b81a6fe99..80b25046024 100644 --- a/intern/cycles/device/queue.cpp +++ b/intern/cycles/device/queue.cpp @@ -2,15 +2,15 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include "device/queue.h" +#include + #include "device/kernel.h" +#include "device/queue.h" #include "util/algorithm.h" #include "util/log.h" #include "util/time.h" -#include - CCL_NAMESPACE_BEGIN DeviceQueue::DeviceQueue(Device *device) : device(device) diff --git a/intern/cycles/graph/node_type.cpp b/intern/cycles/graph/node_type.cpp index 5ade312e48a..2a1aab1fd84 100644 --- a/intern/cycles/graph/node_type.cpp +++ b/intern/cycles/graph/node_type.cpp @@ -4,6 +4,7 @@ #include "graph/node_type.h" +#include "util/log.h" #include "util/transform.h" CCL_NAMESPACE_BEGIN @@ -214,7 +215,7 @@ NodeType *NodeType::add(const char *name_, CreateFunc create_, Type type_, const const ustring name(name_); if (types().find(name) != types().end()) { - fprintf(stderr, "Node type %s registered twice!\n", name_); + LOG(ERROR) << "Node type " << name_ << " registered twice"; assert(0); return nullptr; } diff --git a/intern/cycles/graph/node_type.h b/intern/cycles/graph/node_type.h index 48dda1b75dd..6abf3ee35fc 100644 --- a/intern/cycles/graph/node_type.h +++ b/intern/cycles/graph/node_type.h @@ -5,6 +5,7 @@ #pragma once #include "graph/node_enum.h" + #include "util/array.h" // IWYU pragma: keep #include "util/map.h" #include "util/param.h" diff --git a/intern/cycles/graph/node_xml.cpp b/intern/cycles/graph/node_xml.cpp index ac7270c815f..aa4a06059bb 100644 --- a/intern/cycles/graph/node_xml.cpp +++ b/intern/cycles/graph/node_xml.cpp @@ -7,6 +7,7 @@ # include "graph/node_xml.h" # include "graph/node.h" +# include "util/log.h" # include "util/string.h" # include "util/transform.h" @@ -158,10 +159,8 @@ void xml_read_node(XMLReader &reader, Node *node, const xml_node xml_node) node->set(socket, value); } else { - fprintf(stderr, - "Unknown value \"%s\" for attribute \"%s\".\n", - value.c_str(), - socket.name.c_str()); + LOG(ERROR) << "Unknown value \"" << value.c_str() << "\" for attribute \"" + << socket.name.c_str() << "\""; } break; } diff --git a/intern/cycles/hydra/file_reader.cpp b/intern/cycles/hydra/file_reader.cpp index 93de07c0de6..ac9d7bd1e47 100644 --- a/intern/cycles/hydra/file_reader.cpp +++ b/intern/cycles/hydra/file_reader.cpp @@ -6,6 +6,7 @@ #include "hydra/camera.h" #include "hydra/render_delegate.h" +#include "util/log.h" #include "util/path.h" #include "util/unique_ptr.h" @@ -59,7 +60,7 @@ void HdCyclesFileReader::read(Session *session, const char *filepath, const bool /* Open Stage. */ const UsdStageRefPtr stage = UsdStage::Open(filepath); if (!stage) { - fprintf(stderr, "%s read error\n", filepath); + LOG(ERROR) << "USD failed to read " << filepath; return; } diff --git a/intern/cycles/integrator/denoiser_oidn.cpp b/intern/cycles/integrator/denoiser_oidn.cpp index 829b0accd63..f0990883b8b 100644 --- a/intern/cycles/integrator/denoiser_oidn.cpp +++ b/intern/cycles/integrator/denoiser_oidn.cpp @@ -121,7 +121,7 @@ class OIDNDenoiseContext { const char *custom_weight_path = getenv("CYCLES_OIDN_CUSTOM_WEIGHTS"); if (custom_weight_path) { if (!path_read_binary(custom_weight_path, custom_weights)) { - fprintf(stderr, "Cycles: Failed to load custom OIDN weights!"); + LOG(ERROR) << "Failed to load custom OpenImageDenoise weights"; } } } diff --git a/intern/cycles/integrator/denoiser_oidn_gpu.cpp b/intern/cycles/integrator/denoiser_oidn_gpu.cpp index 92aac3f9cce..32f41735b19 100644 --- a/intern/cycles/integrator/denoiser_oidn_gpu.cpp +++ b/intern/cycles/integrator/denoiser_oidn_gpu.cpp @@ -335,7 +335,7 @@ bool OIDNDenoiserGPU::denoise_create_if_needed(DenoiseContext &context) oidn_filter_, "weights", custom_weights.data(), custom_weights.size()); } else { - fprintf(stderr, "Cycles: Failed to load custom OIDN weights!"); + LOG(ERROR) << "Failed to load custom OpenImageDenoise weights"; } } diff --git a/intern/cycles/scene/osl.cpp b/intern/cycles/scene/osl.cpp index e5cf89ba414..37353b136b8 100644 --- a/intern/cycles/scene/osl.cpp +++ b/intern/cycles/scene/osl.cpp @@ -567,7 +567,7 @@ const char *OSLManager::shader_load_filepath(string filepath) string bytecode; if (!path_read_text(filepath, bytecode)) { - fprintf(stderr, "Cycles shader graph: failed to read file %s\n", filepath.c_str()); + LOG(ERROR) << "Shader graph: failed to read file " << filepath; const OSLShaderInfo info; loaded_shaders[bytecode_hash] = info; /* to avoid repeat tries */ return nullptr; @@ -588,7 +588,7 @@ const char *OSLManager::shader_load_bytecode(const string &hash, const string &b OSLShaderInfo info; if (!info.query.open_bytecode(bytecode)) { - fprintf(stderr, "OSL query error: %s\n", info.query.geterror().c_str()); + LOG(ERROR) << "OSL query error: " << info.query.geterror(); } /* this is a bit weak, but works */ diff --git a/intern/cycles/scene/shader_graph.cpp b/intern/cycles/scene/shader_graph.cpp index 242cc1b77ff..8eefea34904 100644 --- a/intern/cycles/scene/shader_graph.cpp +++ b/intern/cycles/scene/shader_graph.cpp @@ -241,20 +241,16 @@ void ShaderGraph::connect(ShaderOutput *from, ShaderInput *to) assert(from && to); if (to->link) { - fprintf(stderr, "Cycles shader graph connect: input already connected.\n"); + LOG(WARNING) << "Sraph connect: input already connected."; return; } if (from->type() != to->type()) { /* can't do automatic conversion from closure */ if (from->type() == SocketType::CLOSURE) { - fprintf(stderr, - "Cycles shader graph connect: can only connect closure to closure " - "(%s.%s to %s.%s).\n", - from->parent->name.c_str(), - from->name().c_str(), - to->parent->name.c_str(), - to->name().c_str()); + LOG(WARNING) << "Shader graph connect: can only connect closure to closure (" + << from->parent->name.c_str() << "." << from->name().c_str() << " to " + << to->parent->name.c_str() << "." << to->name().c_str() << ")"; return; } @@ -721,7 +717,7 @@ void ShaderGraph::break_cycles(ShaderNode *node, vector &visited, vectorid]) { /* break cycle */ disconnect(input); - fprintf(stderr, "Cycles shader graph: detected cycle in graph, connection removed.\n"); + LOG(WARNING) << "Shader graph: detected cycle in graph, connection removed."; } else if (!visited[depnode->id]) { /* visit dependencies */ @@ -1200,7 +1196,7 @@ void ShaderGraph::dump_graph(const char *filename) FILE *fd = fopen(filename, "w"); if (fd == nullptr) { - printf("Error opening file for dumping the graph: %s\n", filename); + LOG(ERROR) << "Error opening file for dumping the graph: " << filename; return; } diff --git a/intern/cycles/scene/svm.cpp b/intern/cycles/scene/svm.cpp index 4934b4baeb0..82747dcb503 100644 --- a/intern/cycles/scene/svm.cpp +++ b/intern/cycles/scene/svm.cpp @@ -217,9 +217,8 @@ int SVMCompiler::stack_find_offset(const int size) if (!compile_failed) { compile_failed = true; - fprintf(stderr, - "Cycles: out of SVM stack space, shader \"%s\" too big.\n", - current_shader->name.c_str()); + LOG(ERROR) << "Shader graph: out of SVM stack space, shader \"" << current_shader->name + << "\" too big."; } return 0; diff --git a/intern/cycles/session/denoising.cpp b/intern/cycles/session/denoising.cpp index 9df5d091c48..8a893c86a7d 100644 --- a/intern/cycles/session/denoising.cpp +++ b/intern/cycles/session/denoising.cpp @@ -292,8 +292,6 @@ bool DenoiseTask::exec() } out += image.num_channels * image.width; } - - printf("\n"); } return true; diff --git a/intern/cycles/util/guarded_allocator.h b/intern/cycles/util/guarded_allocator.h index 21e2c647cc5..0b5566fbbfa 100644 --- a/intern/cycles/util/guarded_allocator.h +++ b/intern/cycles/util/guarded_allocator.h @@ -152,7 +152,7 @@ size_t util_guarded_get_mem_peak(); (func)(__VA_ARGS__); \ } \ catch (std::bad_alloc &) { \ - fprintf(stderr, "Error: run out of memory!\n"); \ + LOG(ERROR) << "Out of memory"; \ fflush(stderr); \ (progress)->set_error("Out of memory"); \ } \ diff --git a/intern/cycles/util/log.cpp b/intern/cycles/util/log.cpp index 64c153aee51..8408a9dec03 100644 --- a/intern/cycles/util/log.cpp +++ b/intern/cycles/util/log.cpp @@ -14,7 +14,7 @@ CCL_NAMESPACE_BEGIN -LogLevel LOG_LEVEL = DWARNING; +LogLevel LOG_LEVEL = INFO_IMPORTANT; static LogFunction LOG_FUNCTION; static double LOG_START_TIME = time_dt(); @@ -30,6 +30,7 @@ const char *log_level_to_string(const LogLevel level) case WARNING: case DWARNING: return "WARNING"; + case INFO_IMPORTANT: case INFO: return "INFO"; case WORK: @@ -59,7 +60,7 @@ LogLevel log_string_to_level(const string &str) return WARNING; } if (str_lower == "info") { - return FATAL; + return INFO; } if (str_lower == "work") { return WORK; diff --git a/intern/cycles/util/log.h b/intern/cycles/util/log.h index db90db04177..a41cb4b87b4 100644 --- a/intern/cycles/util/log.h +++ b/intern/cycles/util/log.h @@ -15,16 +15,17 @@ CCL_NAMESPACE_BEGIN /* Log Levels */ enum LogLevel { - FATAL = 0, /* Fatal error, application will abort */ - DFATAL = 1, /* Fatal error in debug build only */ - ERROR = 2, /* Error */ - DERROR = 3, /* Error in debug build only */ - WARNING = 4, /* Warning */ - DWARNING = 5, /* Warning in debug build only */ - INFO = 6, /* Info about devices, scene contents and features used. */ - WORK = 7, /* Work being performed and timing/memory stats about that work. */ - STATS = 8, /* Detailed device timing stats. */ - DEBUG = 9, /* Verbose debug messages. */ + FATAL = 0, /* Fatal error, application will abort */ + DFATAL = 1, /* Fatal error in debug build only */ + ERROR = 2, /* Error */ + DERROR = 3, /* Error in debug build only */ + WARNING = 4, /* Warning */ + DWARNING = 5, /* Warning in debug build only */ + INFO_IMPORTANT = 6, /* Important info that is printed by default */ + INFO = 7, /* Info about devices, scene contents and features used. */ + WORK = 8, /* Work being performed and timing/memory stats about that work. */ + STATS = 9, /* Detailed device timing stats. */ + DEBUG = 10, /* Verbose debug messages. */ UNKNOWN = -1, }; @@ -78,19 +79,16 @@ extern LogLevel LOG_LEVEL; #define LOG_STRINGIFY_APPEND(a, b) "" a #b #define LOG_STRINGIFY(x) LOG_STRINGIFY_APPEND("", x) +/* Macro to ensure lazy evaluation of both condition and logging text. */ #ifdef NDEBUG # define LOG_IF(level, condition) \ if constexpr (level != DFATAL && level != DERROR && level != DWARNING) \ - if (LIKELY(!(level <= LOG_LEVEL && (condition)))) \ - ; \ - else \ - LogMessage(level, __FILE__ ":" LOG_STRINGIFY(__LINE__), __func__).stream() + if (UNLIKELY(level <= LOG_LEVEL && (condition))) \ + LogMessage(level, __FILE__ ":" LOG_STRINGIFY(__LINE__), __func__).stream() #else # define LOG_IF(level, condition) \ - if (LIKELY(!(level <= LOG_LEVEL && (condition)))) \ - ; \ - else \ - LogMessage(level, __FILE__ ":" LOG_STRINGIFY(__LINE__), __func__).stream() + if (UNLIKELY(level <= LOG_LEVEL && (condition))) \ + LogMessage(level, __FILE__ ":" LOG_STRINGIFY(__LINE__), __func__).stream() #endif /* Log a message at the desired level. diff --git a/intern/cycles/util/md5.cpp b/intern/cycles/util/md5.cpp index be389c117f8..acd1a5fbeff 100644 --- a/intern/cycles/util/md5.cpp +++ b/intern/cycles/util/md5.cpp @@ -7,6 +7,7 @@ /* Minor modifications done to remove some code and change style. */ #include "util/md5.h" +#include "util/log.h" #include "util/path.h" #include @@ -311,7 +312,7 @@ bool MD5Hash::append_file(const string &filepath) FILE *f = path_fopen(filepath, "rb"); if (!f) { - fprintf(stderr, "MD5: failed to open file %s\n", filepath.c_str()); + LOG(ERROR) << "MD5: failed to open file " << filepath; return false; }