Use LOG() with the printf-like interface (the only way to be thread safe)

This commit is contained in:
David Capello 2020-06-17 17:05:43 -03:00
parent 677b8bf204
commit d75c9c443a
12 changed files with 42 additions and 45 deletions

2
laf

@ -1 +1 @@
Subproject commit 85259c5421f06f55143cba7c69708f01e0fc026b
Subproject commit 0dd4ba1bdd910fb00d2e209d8c3b4454a09ce271

View File

@ -539,7 +539,7 @@ App::~App()
m_instance = NULL;
}
catch (const std::exception& e) {
LOG(ERROR) << "APP: Error: " << e.what() << "\n";
LOG(ERROR, "APP: Error: %s\n", e.what());
os::error_message(e.what());
// no re-throw

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
@ -184,7 +185,7 @@ AppBrushes::AppBrushes()
load(fn);
}
catch (const std::exception& ex) {
LOG(ERROR) << "BRSH: Error loading user brushes: " << ex.what() << "\n";
LOG(ERROR, "BRSH: Error loading user brushes: %s\n", ex.what());
}
}

View File

@ -210,8 +210,8 @@ void Session::removeFromDisk()
}
catch (const std::exception& ex) {
(void)ex;
LOG(ERROR) << "RECO: Session directory cannot be removed, it's not empty.\n"
<< " Error: " << ex.what() << "\n";
LOG(ERROR, "RECO: Session directory cannot be removed, it's not empty.\n"
" Error: %s\n", ex.what());
}
}
@ -265,7 +265,7 @@ void Session::removeDocument(Doc* doc)
markDocumentAsCorrectlyClosed(doc);
}
catch (const std::exception& ex) {
LOG(FATAL) << "Exception deleting document " << ex.what() << "\n";
LOG(FATAL, "Exception deleting document %s\n", ex.what());
}
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -107,7 +107,7 @@ static void output_message(j_common_ptr cinfo)
(*cinfo->err->format_message)(cinfo, buffer);
// Put in the log file if.
LOG(ERROR) << "JPEG: \"" << buffer << "\"\n";
LOG(ERROR, "JPEG: \"%s\"\n", buffer);
// Leave the message for the application.
((struct error_mgr *)cinfo->err)->fop->setError("%s\n", buffer);

View File

@ -72,10 +72,10 @@ void HttpLoader::threadHttpRequest()
LOG("HTTP: Response: %d\n", response.status());
}
catch (const std::exception& e) {
LOG(ERROR) << "HTTP: Unexpected exception sending http request: " << e.what() << "\n";
LOG(ERROR, "HTTP: Unexpected exception sending http request: %s\n", e.what());
}
catch (...) {
LOG(ERROR) << "HTTP: Unexpected unknown exception sending http request\n";
LOG(ERROR, "HTTP: Unexpected unknown exception sending http request\n");
}
delete m_request;

View File

@ -216,7 +216,7 @@ void ToolBox::loadTools()
if (!groupId)
throw base::Exception("The configuration file has a <group> without 'id' or 'text' attributes.");
LOG(VERBOSE) << "TOOL: Group " << groupId << "\n";
LOG(VERBOSE, "TOOL: %s group\n", groupId);
// Find an existent ToolGroup (this is useful in case we are
// reloading tool text/tooltips).
@ -258,7 +258,7 @@ void ToolBox::loadTools()
tool->setDefaultBrushSize(
defaultBrushSize ? std::strtol(defaultBrushSize, nullptr, 10): 1);
LOG(VERBOSE) << "TOOL: Tool " << toolId << " in group " << groupId << " found\n";
LOG(VERBOSE, "TOOL: %s.%s tool\n", groupId, toolId);
loadToolProperties(xmlTool, tool, 0, "left");
loadToolProperties(xmlTool, tool, 1, "right");

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -488,7 +488,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
if (tool) {
KeyPtr key = this->tool(tool);
if (key && tool_key) {
LOG(VERBOSE) << "KEYS: Shortcut for tool " << tool_id << ": " << tool_key << "\n";
LOG(VERBOSE, "KEYS: Shortcut for tool %s: %s\n", tool_id, tool_key);
Accelerator accel(tool_key);
if (!removed)
@ -516,7 +516,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
if (tool) {
KeyPtr key = this->quicktool(tool);
if (key && tool_key) {
LOG(VERBOSE) << "KEYS: Shortcut for quicktool " << tool_id << ": " << tool_key << "\n";
LOG(VERBOSE, "KEYS: Shortcut for quicktool %s: %s\n", tool_id, tool_key);
Accelerator accel(tool_key);
if (!removed)
@ -544,8 +544,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
if (action != KeyAction::None) {
KeyPtr key = this->action(action);
if (key && action_key) {
LOG(VERBOSE) << "KEYS: Shortcut for action " << action_id
<< ": " << action_key << "\n";
LOG(VERBOSE, "KEYS: Shortcut for action %s: %s\n", action_id, action_key);
Accelerator accel(action_key);
if (!removed)
@ -573,8 +572,7 @@ void KeyboardShortcuts::importFile(TiXmlElement* rootElement, KeySource source)
if (action != WheelAction::None) {
KeyPtr key = this->wheelAction(action);
if (key && action_key) {
LOG(VERBOSE) << "KEYS: Shortcut for wheel action " << action_id
<< ": " << action_key << "\n";
LOG(VERBOSE, "KEYS: Shortcut for wheel action %s: %s\n", action_id, action_key);
Accelerator accel(action_key);
if (!removed)

View File

@ -136,7 +136,7 @@ static FontData* load_font(std::map<std::string, FontData*>& fonts,
if (it != fonts.end())
return it->second;
LOG(VERBOSE) << "THEME: Loading font '" << name << "'\n";
LOG(VERBOSE, "THEME: Loading font '%s'\n", name.c_str());
const char* typeStr = xmlFont->Attribute("type");
if (!typeStr)
@ -185,7 +185,7 @@ static FontData* load_font(std::map<std::string, FontData*>& fonts,
font->setAntialias(antialias);
if (!fontFilename.empty())
LOG(VERBOSE) << "THEME: Font file '" << fontFilename << "' found\n";
LOG(VERBOSE, "THEME: Font file '%s' found\n", fontFilename.c_str());
}
else {
throw base::Exception("Invalid type=\"%s\" in '%s' for <font name=\"%s\" ...>\n",
@ -389,7 +389,7 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
FontData* fontData = load_font(m_fonts, xmlFont, xml_filename);
if (idStr && fontData) {
std::string id(idStr);
LOG(VERBOSE) << "THEME: Loading theme font '" << id << "\n";
LOG(VERBOSE, "THEME: Loading theme font %s\n", idStr);
int size = 10;
const char* sizeStr = xmlFont->Attribute("size");
@ -425,7 +425,7 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
std::string id = xmlDim->Attribute("id");
uint32_t value = strtol(xmlDim->Attribute("value"), NULL, 10);
LOG(VERBOSE) << "THEME: Loading dimension '" << id << "\n";
LOG(VERBOSE, "THEME: Loading dimension %s\n", id.c_str());
m_dimensions_by_id[id] = value;
xmlDim = xmlDim->NextSiblingElement();
@ -446,7 +446,7 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
(value & 0xff00) >> 8,
(value & 0xff));
LOG(VERBOSE) << "THEME: Loading color " << id << "\n";
LOG(VERBOSE, "THEME: Loading color %s\n", id.c_str());
m_colors_by_id[id] = color;
xmlColor = xmlColor->NextSiblingElement();
@ -467,7 +467,7 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
int w = (xmlPart->Attribute("w") ? scale*strtol(xmlPart->Attribute("w"), nullptr, 10): 0);
int h = (xmlPart->Attribute("h") ? scale*strtol(xmlPart->Attribute("h"), nullptr, 10): 0);
LOG(VERBOSE) << "THEME: Loading part " << part_id << "\n";
LOG(VERBOSE, "THEME: Loading part %s\n", part_id);
SkinPartPtr part = m_parts_by_id[part_id];
if (!part)
@ -504,7 +504,7 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
int focusx = scale*std::strtol(xmlPart->Attribute("focusx"), NULL, 10);
int focusy = scale*std::strtol(xmlPart->Attribute("focusy"), NULL, 10);
LOG(VERBOSE) << "THEME: Loading cursor '" << cursorName << "'\n";
LOG(VERBOSE, "THEME: Loading cursor '%s'\n", cursorName.c_str());
auto it = m_cursors.find(cursorName);
if (it != m_cursors.end() && it->second != nullptr) {
@ -622,8 +622,7 @@ void SkinTheme::loadXml(BackwardCompatibility* backward)
while (xmlLayer) {
const std::string layerName = xmlLayer->Value();
LOG(VERBOSE) << "THEME: Layer " << layerName
<< " for " << style_id << "\n";
LOG(VERBOSE, "THEME: Layer %s for %s\n", layerName.c_str(), style_id);
ui::Style::Layer layer;

View File

@ -1,5 +1,5 @@
// Aseprite Config Library
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2014-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -96,7 +96,8 @@ public:
m_ini.SetMultiLine();
SI_Error err = m_ini.LoadFile(file.get());
if (err != SI_OK) {
LOG(ERROR) << "CFG: Error " << err << " loading configuration from " << m_filename << "\n";
LOG(ERROR, "CFG: Error %d loading configuration from %s\n",
(int)err, m_filename.c_str());
}
}
}
@ -106,7 +107,8 @@ public:
if (file) {
SI_Error err = m_ini.SaveFile(file.get());
if (err != SI_OK) {
LOG(ERROR) << "CFG: Error " << err << " saving configuration into " << m_filename << "\n";
LOG(ERROR, "CFG: Error %d saving configuration into %s\n",
(int)err, m_filename.c_str());
}
}
}

View File

@ -1,4 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2020 Igara Studio S.A.
// Copyright (c) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -25,7 +26,7 @@
namespace doc {
namespace file {
Palette* load_gpl_file(const char *filename)
Palette* load_gpl_file(const char* filename)
{
std::ifstream f(FSTREAM_PATH(filename));
if (f.bad()) return NULL;
@ -93,7 +94,7 @@ Palette* load_gpl_file(const char *filename)
base::trim_string(comment, comment);
if (!comment.empty()) {
LOG(VERBOSE) << "PAL: " << filename << " comment: " << comment << "\n";
LOG(VERBOSE, "PAL: %s comment: %s\n", filename, comment.c_str());
pal->setComment(comment);
}

View File

@ -173,9 +173,8 @@ void Widget::setBgColor(gfx::Color color)
#ifdef _DEBUG
if (m_style) {
LOG(WARNING) << "UI: " << typeid(*this).name()
<< ": Warning setting bgColor to a widget with style ("
<< m_style->id() << ")\n";
LOG(WARNING, "UI: %s: Warning setting bgColor to a widget with style (%s)\n",
typeid(*this).name(), m_style->id().c_str());
}
#endif
}
@ -707,9 +706,8 @@ void Widget::setBorder(const Border& br)
#ifdef _DEBUG
if (m_style) {
LOG(WARNING) << "UI: " << typeid(*this).name()
<< ": Warning setting border to a widget with style ("
<< m_style->id() << ")\n";
LOG(WARNING, "UI: %s: Warning setting border to a widget with style (%s)\n",
typeid(*this).name(), m_style->id().c_str());
}
#endif
}
@ -720,9 +718,8 @@ void Widget::setChildSpacing(int childSpacing)
#ifdef _DEBUG
if (m_style) {
LOG(WARNING) << "UI: " << typeid(*this).name()
<< ": Warning setting child spacing to a widget with style ("
<< m_style->id() << ")\n";
LOG(WARNING, "UI: %s: Warning setting child spacing to a widget with style (%s)\n",
typeid(*this).name(), m_style->id().c_str());
}
#endif
}
@ -734,9 +731,8 @@ void Widget::noBorderNoChildSpacing()
#ifdef _DEBUG
if (m_style) {
LOG(WARNING) << "UI: " << typeid(*this).name()
<< ": Warning setting no border to a widget with style ("
<< m_style->id() << ")\n";
LOG(WARNING, "UI: %s: Warning setting no border to a widget with style (%s)\n",
typeid(*this).name(), m_style->id().c_str());
}
#endif
}