mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Wrap all TRACE() calls in data recovery functions with RECO_TRACE()
In this way we can completely disable the log of data recovery events. In a future we might offer a way to log all these events in a log file (probably included in crash reports).
This commit is contained in:
parent
b7f06c1366
commit
25cb258f76
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2018-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2018-2023 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -20,6 +20,7 @@
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/context.h"
|
||||
#include "app/crash/log.h"
|
||||
#include "app/crash/recovery_config.h"
|
||||
#include "app/crash/session.h"
|
||||
#include "app/doc.h"
|
||||
@ -83,7 +84,7 @@ void BackupObserver::stop()
|
||||
|
||||
void BackupObserver::onAddDocument(Doc* document)
|
||||
{
|
||||
TRACE("RECO: Observe document %p\n", document);
|
||||
RECO_TRACE("RECO: Observe document %p\n", document);
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
m_documents.push_back(document);
|
||||
@ -91,7 +92,7 @@ void BackupObserver::onAddDocument(Doc* document)
|
||||
|
||||
void BackupObserver::onRemoveDocument(Doc* doc)
|
||||
{
|
||||
TRACE("RECO: Remove document %p\n", doc);
|
||||
RECO_TRACE("RECO: Remove document %p\n", doc);
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
base::remove_from_container(m_documents, doc);
|
||||
@ -108,13 +109,13 @@ void BackupObserver::onRemoveDocument(Doc* doc)
|
||||
// in m_closedDocs list anyway so we call markAsBackedUp(), and
|
||||
// then it's deleted from ClosedDocs::backgroundThread()
|
||||
|
||||
TRACE("RECO: Adding to CLOSEDOC %p\n", doc);
|
||||
RECO_TRACE("RECO: Adding to CLOSEDOC %p\n", doc);
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
m_closedDocs.push_back(doc);
|
||||
}
|
||||
else {
|
||||
TRACE("RECO: Removing doc %p from session\n", doc);
|
||||
RECO_TRACE("RECO: Removing doc %p from session\n", doc);
|
||||
m_session->removeDocument(doc);
|
||||
}
|
||||
}
|
||||
@ -135,8 +136,8 @@ void BackupObserver::backgroundThread()
|
||||
while (!m_done) {
|
||||
m_wakeup.wait_for(lock, std::chrono::seconds(waitFor));
|
||||
|
||||
TRACE("RECO: Start backup process for %d documents\n",
|
||||
m_documents.size() + m_closedDocs.size());
|
||||
RECO_TRACE("RECO: Start backup process for %d documents\n",
|
||||
m_documents.size() + m_closedDocs.size());
|
||||
|
||||
SwitchBackupIcon icon;
|
||||
base::Chrono chrono;
|
||||
@ -151,10 +152,10 @@ void BackupObserver::backgroundThread()
|
||||
for (auto it=m_closedDocs.begin(); it != m_closedDocs.end(); ) {
|
||||
Doc* doc = *it;
|
||||
|
||||
TRACE("RECO: Save backup data for %p...\n", doc);
|
||||
RECO_TRACE("RECO: Save backup data for %p...\n", doc);
|
||||
|
||||
if (saveDocData(doc)) {
|
||||
TRACE("RECO: Doc %p is fully backed up\n", doc);
|
||||
RECO_TRACE("RECO: Doc %p is fully backed up\n", doc);
|
||||
|
||||
it = m_closedDocs.erase(it);
|
||||
doc->markAsBackedUp();
|
||||
@ -168,7 +169,7 @@ void BackupObserver::backgroundThread()
|
||||
|
||||
waitFor = (somethingLocked ? lockedPeriod: normalPeriod);
|
||||
|
||||
TRACE("RECO: Backup process done (%.16g)\n", chrono.elapsed());
|
||||
RECO_TRACE("RECO: Backup process done (%.16g)\n", chrono.elapsed());
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,10 +181,10 @@ bool BackupObserver::saveDocData(Doc* doc)
|
||||
return true;
|
||||
|
||||
if (doc->inhibitBackup()) {
|
||||
TRACE("RECO: Document '%d' backup is temporarily inhibited\n", doc->id());
|
||||
RECO_TRACE("RECO: Document '%d' backup is temporarily inhibited\n", doc->id());
|
||||
}
|
||||
else if (!m_session->saveDocumentChanges(doc)) {
|
||||
TRACE("RECO: Document '%d' backup was canceled by UI\n", doc->id());
|
||||
RECO_TRACE("RECO: Document '%d' backup was canceled by UI\n", doc->id());
|
||||
}
|
||||
else {
|
||||
#ifdef TEST_BACKUP_INTEGRITY
|
||||
@ -192,18 +193,18 @@ bool BackupObserver::saveDocData(Doc* doc)
|
||||
m_session->restoreBackupDocById(doc->id(), nullptr));
|
||||
DocDiff diff = compare_docs(doc, copy.get());
|
||||
if (diff.anything) {
|
||||
TRACEARGS("RECO: Differences:",
|
||||
diff.canvas ? "canvas": "",
|
||||
diff.totalFrames ? "totalFrames": "",
|
||||
diff.frameDuration ? "frameDuration": "",
|
||||
diff.tags ? "tags": "",
|
||||
diff.palettes ? "palettes": "",
|
||||
diff.tilesets ? "tilesets": "",
|
||||
diff.layers ? "layers": "",
|
||||
diff.cels ? "cels": "",
|
||||
diff.images ? "images": "",
|
||||
diff.colorProfiles ? "colorProfiles": "",
|
||||
diff.gridBounds ? "gridBounds": "");
|
||||
RECO_TRACE("RECO: Differences: %s %s %s %s %s %s %s %s %s %s %s\n",
|
||||
diff.canvas ? "canvas": "",
|
||||
diff.totalFrames ? "totalFrames": "",
|
||||
diff.frameDuration ? "frameDuration": "",
|
||||
diff.tags ? "tags": "",
|
||||
diff.palettes ? "palettes": "",
|
||||
diff.tilesets ? "tilesets": "",
|
||||
diff.layers ? "layers": "",
|
||||
diff.cels ? "cels": "",
|
||||
diff.images ? "images": "",
|
||||
diff.colorProfiles ? "colorProfiles": "",
|
||||
diff.gridBounds ? "gridBounds": "");
|
||||
|
||||
Doc* copyDoc = copy.release();
|
||||
ui::execute_from_ui_thread(
|
||||
@ -212,14 +213,14 @@ bool BackupObserver::saveDocData(Doc* doc)
|
||||
});
|
||||
}
|
||||
else {
|
||||
TRACE("RECO: No differences\n");
|
||||
RECO_TRACE("RECO: No differences\n");
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
TRACE("RECO: Document '%d' is locked\n", doc->id());
|
||||
RECO_TRACE("RECO: Document '%d' is locked\n", doc->id());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2023 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -12,6 +12,7 @@
|
||||
#include "app/crash/data_recovery.h"
|
||||
|
||||
#include "app/crash/backup_observer.h"
|
||||
#include "app/crash/log.h"
|
||||
#include "app/crash/session.h"
|
||||
#include "app/pref/preferences.h"
|
||||
#include "app/resource_finder.h"
|
||||
@ -23,8 +24,6 @@
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#define RECO_TRACE(...) // TRACE
|
||||
|
||||
namespace app {
|
||||
namespace crash {
|
||||
|
||||
|
16
src/app/crash/log.h
Normal file
16
src/app/crash/log.h
Normal file
@ -0,0 +1,16 @@
|
||||
// Aseprite
|
||||
// Copyright (c) 2023 Igara Studio S.A.
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
|
||||
#ifndef APP_CRASH_LOG_H_INCLUDED
|
||||
#define APP_CRASH_LOG_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "base/debug.h"
|
||||
|
||||
// TODO should we log some events in release?
|
||||
#define RECO_TRACE(...) // TRACE(__VA_ARGS__)
|
||||
|
||||
#endif
|
@ -14,6 +14,7 @@
|
||||
#include "app/console.h"
|
||||
#include "app/crash/doc_format.h"
|
||||
#include "app/crash/internals.h"
|
||||
#include "app/crash/log.h"
|
||||
#include "app/doc.h"
|
||||
#include "base/convert_to.h"
|
||||
#include "base/exception.h"
|
||||
@ -152,7 +153,7 @@ private:
|
||||
if (!ver)
|
||||
continue;
|
||||
|
||||
TRACE("RECO: Restoring %s #%d v%d\n", prefix, id, ver);
|
||||
RECO_TRACE("RECO: Restoring %s #%d v%d\n", prefix, id, ver);
|
||||
|
||||
std::string fn = prefix;
|
||||
fn.push_back('-');
|
||||
@ -166,11 +167,11 @@ private:
|
||||
obj = (this->*readMember)(s);
|
||||
|
||||
if (obj) {
|
||||
TRACE("RECO: %s #%d v%d restored successfully\n", prefix, id, ver);
|
||||
RECO_TRACE("RECO: %s #%d v%d restored successfully\n", prefix, id, ver);
|
||||
return obj;
|
||||
}
|
||||
else {
|
||||
TRACE("RECO: %s #%d v%d was not restored\n", prefix, id, ver);
|
||||
RECO_TRACE("RECO: %s #%d v%d was not restored\n", prefix, id, ver);
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,7 +188,7 @@ private:
|
||||
m_docFormatVer = read16(s);
|
||||
if (s.eof()) m_docFormatVer = DOC_FORMAT_VERSION_0;
|
||||
|
||||
TRACE("RECO: internal format version=%d\n", m_docFormatVer);
|
||||
RECO_TRACE("RECO: internal format version=%d\n", m_docFormatVer);
|
||||
|
||||
// Load DocumentInfo only
|
||||
if (m_loadInfo) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019-2022 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2023 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -13,6 +13,7 @@
|
||||
|
||||
#include "app/console.h"
|
||||
#include "app/context.h"
|
||||
#include "app/crash/log.h"
|
||||
#include "app/crash/read_document.h"
|
||||
#include "app/crash/recovery_config.h"
|
||||
#include "app/crash/write_document.h"
|
||||
@ -236,7 +237,7 @@ bool Session::saveDocumentChanges(Doc* doc)
|
||||
app::Context ctx;
|
||||
std::string dir = base::join_path(m_path,
|
||||
base::convert_to<std::string>(doc->id()));
|
||||
TRACE("RECO: Saving document '%s'...\n", dir.c_str());
|
||||
RECO_TRACE("RECO: Saving document '%s'...\n", dir.c_str());
|
||||
|
||||
// Create directory for document
|
||||
if (!base::is_directory(dir))
|
||||
@ -375,7 +376,7 @@ void Session::markDocumentAsCorrectlyClosed(app::Doc* doc)
|
||||
|
||||
std::string openFn = base::join_path(dir, kOpenFilename);
|
||||
if (base::is_file(openFn)) {
|
||||
TRACE("RECO: Document was closed correctly, deleting file '%s'\n", openFn.c_str());
|
||||
RECO_TRACE("RECO: Document was closed correctly, deleting file '%s'\n", openFn.c_str());
|
||||
base::delete_file(openFn);
|
||||
}
|
||||
}
|
||||
@ -389,7 +390,7 @@ void Session::deleteDirectory(const std::string& dir)
|
||||
for (auto& item : base::list_files(dir)) {
|
||||
std::string objfn = base::join_path(dir, item);
|
||||
if (base::is_file(objfn)) {
|
||||
TRACE("RECO: Deleting file '%s'\n", objfn.c_str());
|
||||
RECO_TRACE("RECO: Deleting file '%s'\n", objfn.c_str());
|
||||
base::delete_file(objfn);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "app/crash/doc_format.h"
|
||||
#include "app/crash/internals.h"
|
||||
#include "app/crash/log.h"
|
||||
#include "app/doc.h"
|
||||
#include "base/convert_to.h"
|
||||
#include "base/fs.h"
|
||||
@ -355,7 +356,7 @@ private:
|
||||
// Rotate versions and add the latest one
|
||||
versions.rotateRevisions(obj->version());
|
||||
|
||||
TRACE(" - Saved %s #%d v%d\n", prefix, obj->id(), obj->version());
|
||||
RECO_TRACE(" - Saved %s #%d v%d\n", prefix, obj->id(), obj->version());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -365,11 +366,11 @@ private:
|
||||
m_deleteFiles.erase(m_deleteFiles.end()-1);
|
||||
|
||||
try {
|
||||
TRACE(" - Deleting <%s>\n", file.c_str());
|
||||
RECO_TRACE(" - Deleting <%s>\n", file.c_str());
|
||||
base::delete_file(file);
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
TRACE(" - Cannot delete <%s>\n", file.c_str());
|
||||
RECO_TRACE(" - Cannot delete <%s>\n", file.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user