Patch level : 12.0 nopatch

Files correlati     :
Commento        :

aggiunto un meccanismo di trace nei programmi

Interno:

Si attiva mettendo nel paragrafo Main di studio.ini
TRACE = X
This commit is contained in:
Alessandro Bonazzi 2021-10-15 07:24:21 +02:00
parent 509d76607f
commit 0e9502d07d
5 changed files with 43 additions and 19 deletions

View File

@ -586,7 +586,15 @@ void TApplication::run(
xvt_vobj_set_attr(NULL_WIN, ATTR_APPL_VERSION_STRING, (long)(const char*)ver);
}
set_xvt_hooks();
__set_trace();
const struct tm * timeloc = xvt_time_now();
TRACE("");
TRACE("----------");
TRACE("%s %s - %s %02d:%02d:%02d", argv[0], argv[1], today.string(), timeloc->tm_hour, timeloc->tm_min, timeloc->tm_sec);
TRACE("----------");
set_xvt_hooks();
_running = TRUE;
xvt_app_create(argc, argv, 0L, task_eh, &cfg);

View File

@ -336,6 +336,12 @@ bool delete_box(const char* fmt, ...)
return r == RESP_DEFAULT;
}
HIDDEN bool __traceon = false;
void __set_trace()
{
__traceon = ini_get_bool(CONFIG_STUDIO, "Main", "TRACE");
}
// @doc EXTERNAL
// @msg __trace | Permette di mandare dei messaggi nel file trace.log
bool __trace(
@ -347,21 +353,31 @@ bool __trace(
//
// @rdesc Ritorna non 0 se riesca ad aprire il file trace.log
{
static FILE* f = NULL;
if (f == NULL)
fopen_s(&f, "trace.log", "w");
if (f != NULL)
{
buildmsg();
fprintf(f, "%s\n", msg);
fflush(f);
}
return f != NULL;
static FILE* f = nullptr;
if (__traceon)
{
if (f == nullptr)
fopen_s(&f, "trace.log", "a");
if (f != nullptr)
{
buildmsg();
fprintf(f, "%s\n", msg);
fflush(f);
}
return f != NULL;
}
return true;
}
bool __tracemem(const char* msg)
{
unsigned long mem = xvt_sys_get_free_memory_kb();
return __trace("%5lu Kb - %s", mem, msg);
if (__traceon)
{
unsigned long mem = xvt_sys_get_free_memory_kb();
return __trace("%5lu Kb - %s", mem, msg);
}
return true;
}

View File

@ -27,6 +27,7 @@ extern "C" {
bool cantread_box(const char* filename);
bool cantwrite_box(const char* filename);
bool cantaccess_box(const char* filename);
void __set_trace();
bool __trace(const char* fmt, ...);
bool __tracemem(const char* fmt);
@ -105,15 +106,10 @@ extern "C" {
// Utilizzata in fase di debug (definire il simbolo TRC in compilazione)
#ifdef TRC
// @doc EXTERNAL
// @msg TRACE | Macro che richiama la funzione <m __trace>
#define TRACE __trace
#define TRACEMEM(msg) __tracemem(msg)
#else
#define TRACE 1 ? 0 : __trace
#define TRACEMEM(msg) 0
#endif
#endif // __CHECKS_H

View File

@ -139,6 +139,7 @@ bool TLog_report::log(int sev, const char* msg)
{
TText_recordset* csv = (TText_recordset*)recordset();
bool ok = csv != NULL;
TRACE("%d - %s", sev, msg);
if (ok)
{
//controlla se la stringa esiste gia'

View File

@ -757,6 +757,7 @@ void execute_transactions(TArray & transactions, TLog_report & log, bool interac
pref.rtrim(1);
while (i >= 0)
{
TRACE("Salvataggio registrazione %d", i);
if (t.executer() == table && t.name().starts_with(pref))
{
t.write();
@ -783,8 +784,10 @@ void execute_transactions(TArray & transactions, TLog_report & log, bool interac
app << " -u" << user();
TExternal_app cmd(app);
cmd.run();
TRACE("Aggiornamento registrazione %d", i);
cmd.run();
list_files(filemask, files);
TRACE("Aggiornamneto log");
FOR_EACH_ARRAY_ROW(files, r, str)
{
TTransaction t(*str);