From 72093df9fdf281ccd581baf5993bdc2ec6957342 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 3 Jan 2016 20:35:53 +1000 Subject: Clean up logging, removing most of the printf's. --- src/libraries/LumbrJack.c | 2 +- src/libraries/Runnr.c | 60 ++++++++++++++++++++--------------------- src/libraries/SledjHamr.c | 68 ++++++++++++++++++++++------------------------- 3 files changed, 63 insertions(+), 67 deletions(-) (limited to 'src/libraries') diff --git a/src/libraries/LumbrJack.c b/src/libraries/LumbrJack.c index 8683357..3bb67e9 100644 --- a/src/libraries/LumbrJack.c +++ b/src/libraries/LumbrJack.c @@ -19,7 +19,7 @@ int HamrTime(char *argv0, void *main, int logDom) if (!eina_init()) { - printf("Can't load eina library, nothing else will work!\n"); + fprintf(stderr, "Can't load eina library, nothing else will work!\n"); exit(0); } diff --git a/src/libraries/Runnr.c b/src/libraries/Runnr.c index 5ec5a9c..04547b4 100644 --- a/src/libraries/Runnr.c +++ b/src/libraries/Runnr.c @@ -60,12 +60,12 @@ static int traceBack(lua_State *L) lua_Debug ar; int i, top = lua_gettop(L), b = 1; -// printf("Stack is %d deep\n", top); +// PI("Stack is %d deep", top); // for (i = 1; i <= top; i++) // dumpStack(L, i); if (top) - printf("Lua error - %s\n", lua_tostring(L, 1)); + PE("Lua error - %s", lua_tostring(L, 1)); i = 0; while (lua_getstack(L, i++, &ar)) @@ -74,15 +74,15 @@ static int traceBack(lua_State *L) { if (NULL == ar.name) ar.name = "DUNNO"; - printf(" Lua backtrace %d - %s %s %s @ %s : %d\n", i, ar.what, ar.namewhat, ar.name, ar.short_src, ar.currentline); + PE(" Lua backtrace %d - %s %s %s @ %s : %d", i, ar.what, ar.namewhat, ar.name, ar.short_src, ar.currentline); b = 0; } else - printf(" Failed to get trace line!\n"); + PE(" Failed to get trace line!"); } if (b) - printf(" NO BACKTRACE!\n"); + PE(" NO BACKTRACE!"); return 0; } @@ -99,7 +99,7 @@ static void printLuaError(int err, char *string, lua_State *L) case LUA_ERRERR: err_type = "error handler"; break; default: err_type = "unknown"; break; } - printf("Error running - %s, \n %s - %s\n", string, err_type, lua_tostring(L, -1)); + PW("Error running - %s, \n %s - %s", string, err_type, lua_tostring(L, -1)); } static int panics = 0; @@ -109,9 +109,9 @@ static int _panic(lua_State *L) // Stack usage [-0, +0, m] // of memory in the following lua_tostring() call. panics++; if (panics) - printf("Lua PANICS!!!!!"); + PE("Lua PANICS!!!!!"); else - printf("Lua PANIC!!!!!: %s", lua_tostring(L, -1)); // Stack usage [-0, +0, m] + PE("Lua PANIC!!!!!: %s", lua_tostring(L, -1)); // Stack usage [-0, +0, m] // The docs say that this will cause an exit(EXIT_FAILURE) if we return, // and that we we should long jump some where to avoid that. This is only // called for things not called from a protected environment. We always @@ -147,7 +147,7 @@ void doLuaString(lua_State *L, char *string, char *module) { const char *err = lua_tostring(L, 1); - printf("Error parsing - %s, ERROR %s", string, err); + PE("Error parsing - %s, ERROR %s", string, err); } else { @@ -159,12 +159,12 @@ void doLuaString(lua_State *L, char *string, char *module) // Consistancy would be good, just sayin'. if (0 == lua_setfenv(L, _A)) { - printf("Error setting environment for - %s", string); + PE("Error setting environment for - %s", string); return; } } -//printf("doLuaString(%s)\n", string); +//PD("doLuaString(%s)\", string); if ((err = lua_pcall(L, 0, LUA_MULTRET, _T))) printLuaError(err, string, L); } @@ -174,7 +174,7 @@ static void _stopScript(script *s) { scriptMessage *sm0, *sm1; -//printf("^^^^^^^^^^^^^^^^^^^_stop(, %s)\n", s->name); +//PD("^^^^^^^^^^^^^^^^^^^_stop(, %s)", s->name); if (s->L) lua_close(s->L); s->L = NULL; if (s->timer) ecore_timer_del(s->timer); s->timer = NULL; EINA_CLIST_FOR_EACH_ENTRY_SAFE(sm0, sm1, &(s->messages), scriptMessage, node) @@ -210,7 +210,7 @@ static void _workerFunction(void *data, Ecore_Thread *thread) if (RUNNR_READY == s->status) { -//printf("_workerFunction() READY %s\n", s->name); +//PD("_workerFunction() READY %s", s->name); if ((msg = (scriptMessage *) eina_clist_head(&(s->messages)))) { eina_clist_remove(&(msg->node)); @@ -226,7 +226,7 @@ static void _workerFunction(void *data, Ecore_Thread *thread) { int err; -//printf("_workerFunction() STARTING %s\n", s->name); +//PD("_workerFunction() STARTING %s", s->name); s->status = RUNNR_RUNNING; s->L = luaL_newstate(); // Sets a standard allocator and panic function. @@ -243,7 +243,7 @@ static void _workerFunction(void *data, Ecore_Thread *thread) if (err != 0) { s->status = RUNNR_FINISHED; - printf("Error loading compiled Lua %s.", s->binName); + PE("Error loading compiled Lua %s.", s->binName); } gettimeofday(&s->startTime, NULL); } @@ -254,7 +254,7 @@ static void _workerFunction(void *data, Ecore_Thread *thread) { int stat; -//printf("_workerFunction() RUNNING %s %s\n", s->name, message); +//PD("_workerFunction() RUNNING %s %s", s->name, message); // Resume running the script. // lua_resume() needs a Lua thread, and the initial Lua state is a thread. // Other Lua threads have their own state, but share the environment with the initial state. @@ -270,7 +270,7 @@ static void _workerFunction(void *data, Ecore_Thread *thread) s->status = RUNNR_FINISHED; else if (stat != LUA_YIELD) { - printf("lua_resume error at %s\n", s->name); + PE("lua_resume error at %s", s->name); printLuaError(stat, s->name, s->L); s->status = RUNNR_FINISHED; } @@ -288,7 +288,7 @@ static void _workerFunction(void *data, Ecore_Thread *thread) // Start again from the top when Ecore_Thread has a spare thread ready, unless the script finished. if (RUNNR_FINISHED == s->status) { -//printf("_workerFunction() FINISHED %s\n", s->name); +//PD("_workerFunction() FINISHED %s", s->name); #if THREADIT ecore_thread_cancel(thread); #else @@ -297,7 +297,7 @@ static void _workerFunction(void *data, Ecore_Thread *thread) } else if (RUNNR_WAIT == s->status) { -;//printf("_workerFunction() WAIT %s\n", s->name); +;//PD("_workerFunction() WAIT %s", s->name); } #if THREADIT else if (RUNNR_READY == s->status) @@ -323,7 +323,7 @@ static void _cancel(void *data, Ecore_Thread *thread) s->status = RUNNR_FINISHED; eina_clist_remove(&(s->node)); if (s->SID[0]) ecore_thread_global_data_del(s->SID); s->SID[0] = 0; -//printf("^^^^^^^^^^^^^^^^^^^_del(, %s)\n", s->name); +//PD("^^^^^^^^^^^^^^^^^^^_del(, %s)", s->name); // TODO - Perhaps have our own deletion callback to pass back? releaseScript(s); #if THREADIT @@ -444,11 +444,11 @@ static void _compileThread(void *data, Ecore_Thread *thread) compiler->bugCount++; #if COMPILE_OUTPUT if (LUA_ERRSYNTAX == err) - printf("Lua syntax error in %s: %s\n", name, lua_tostring(L, -1)); + PI("Lua syntax error in %s: %s", name, lua_tostring(L, -1)); else if (LUA_ERRFILE == err) - printf("Lua compile file error in %s: %s\n", name, lua_tostring(L, -1)); + PE("Lua compile file error in %s: %s", name, lua_tostring(L, -1)); else if (LUA_ERRMEM == err) - printf("Lua compile memory allocation error in %s: %s\n", name, lua_tostring(L, -1)); + PC("Lua compile memory allocation error in %s: %s", name, lua_tostring(L, -1)); #endif } else @@ -462,28 +462,28 @@ static void _compileThread(void *data, Ecore_Thread *thread) if (err) { compiler->bugCount++; - printf("Lua compile file error writing to %s\n", name); + PE("Lua compile file error writing to %s", name); } fclose(out); } else { compiler->bugCount++; - printf("CRITICAL! Unable to open file %s for writing!\n", name); + PE("CRITICAL! Unable to open file %s for writing!", name); } } } else if (!compiler->doConstants) { compiler->bugCount++; - printf("Can't create a new Lua state!\n"); + PC("Can't create a new Lua state!"); } } else { compiler->bugCount++; #if COMPILE_OUTPUT - printf("Nothing for Lua to compile!\n"); + PW("Nothing for Lua to compile!"); #endif } } @@ -544,8 +544,8 @@ void takeScript(script *s) { #if THREADIT Eina_Lock_Result result = eina_lock_take(&s->mutex); - if (EINA_LOCK_DEADLOCK == result) printf("Script %s IS DEADLOCKED!\n", s->name); - if (EINA_LOCK_FAIL == result) printf("Script %s LOCK FAILED!\n", s->name); + if (EINA_LOCK_DEADLOCK == result) PE("Script %s IS DEADLOCKED!", s->name); + if (EINA_LOCK_FAIL == result) PE("Script %s LOCK FAILED!", s->name); #endif } @@ -861,7 +861,7 @@ int push_lua(lua_State *L, char *params, ...) // Stack usage [-0, +n, em] { if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, m] char *t = va_arg(vl, char *); -//printf("push_lua %s string %s\n", p, t); +//PD("push_lua %s string %s", p, t); lua_pushstring(L, t); // Stack usage [-0, +1, m] break; } diff --git a/src/libraries/SledjHamr.c b/src/libraries/SledjHamr.c index 10eeca5..2fb9019 100644 --- a/src/libraries/SledjHamr.c +++ b/src/libraries/SledjHamr.c @@ -38,7 +38,7 @@ static boolean checkConnection(Connection *conn, char *func, connType wanted, bo if ((conn->type != CT_CLIENT) && (conn->type != CT_SERVER)) { result = FALSE; - printf("CONNECTION OBJECT in %s() is of unknown type %d\n", func, (int) conn->type); + PE("CONNECTION OBJECT in %s() is of unknown type %d", func, (int) conn->type); } else if (conn->type != wanted) { @@ -47,43 +47,43 @@ static boolean checkConnection(Connection *conn, char *func, connType wanted, bo { case CT_CLIENT : if (conn->type == CT_SERVER) - printf("INVALID CONNECTION OBJECT in %s(), it might be a server object!\n", func); + PE("INVALID CONNECTION OBJECT in %s(), it might be a server object!", func); else - printf("INVALID CONNECTION OBJECT in %s(), type is %d!\n", func, (int) conn->type); + PE("INVALID CONNECTION OBJECT in %s(), type is %d!", func, (int) conn->type); if (conn->conn.client.myServer == NULL) - printf("CONNECTION OBJECT in %s() is a local client, but should be a remote client mirror!\n", func); + PE("CONNECTION OBJECT in %s() is a local client, but should be a remote client mirror!", func); break; case CT_SERVER : if (conn->type == CT_CLIENT) - printf("INVALID CONNECTION OBJECT in %s(), it might be a client object!\n", func); + PE("INVALID CONNECTION OBJECT in %s(), it might be a client object!", func); else - printf("INVALID CONNECTION OBJECT in %s(), type is %d!\n", func, (int) conn->type); + PE("INVALID CONNECTION OBJECT in %s(), type is %d!", func, (int) conn->type); if (isLocal) { if (conn->conn.server.clients == NULL) - printf("CONNECTION OBJECT in %s() is a remote server mirror, but should be a local server!\n", func); + PE("CONNECTION OBJECT in %s() is a remote server mirror, but should be a local server!", func); } else { if (conn->conn.server.clients != NULL) - printf("CONNECTION OBJECT in %s() is a local server, but should be a remote server mirror!\n", func); + PE("CONNECTION OBJECT in %s() is a local server, but should be a remote server mirror!", func); } break; default : - printf("CONNECTION OBJECT in %s(), silly coder asked for an unknown type!""\n", func); + PE("CONNECTION OBJECT in %s(), silly coder asked for an unknown type!", func); break; } if (NULL == conn->name) { result = FALSE; - printf("CONNECTION OBJECT in %s() has no name!\n", func); + PE("CONNECTION OBJECT in %s() has no name!", func); } } -//if (result) printf("%s(\"%s\")\n", func, conn->name); +//if (result) PD("%s(\"%s\")", func, conn->name); return result; } @@ -102,11 +102,11 @@ void sendBack(Connection *conn, const char *SID, const char *message, ...) va_end(args); buf[length++] = '\n'; buf[length] = '\0'; -// printf("sendBack(%s", buf); +// PD("sendBack(%s", buf); // ecore_con_client_send(client, buf, length); // ecore_con_client_flush(client); //Connection *conn = ecore_con_client_data_get(client); -if (conn) send2(conn, SID, buf); else printf("sendBack() can't find Connection!\n"); +if (conn) send2(conn, SID, buf); else PE("sendBack() can't find Connection!"); } void sendForth(Connection *conn, const char *SID, const char *message, ...) @@ -123,11 +123,11 @@ void sendForth(Connection *conn, const char *SID, const char *message, ...) va_end(args); buf[length++] = '\n'; buf[length] = '\0'; -// printf("sendForth(%s", buf); +// PD("sendForth(%s", buf); // ecore_con_server_send(server, buf, length); // ecore_con_server_flush(server); //Connection *conn = ecore_con_server_data_get(server); -if (conn) send2(conn, SID, buf); else printf("sendForth() can't find Connection!\n"); +if (conn) send2(conn, SID, buf); else PE("sendForth() can't find Connection!"); } void send2(Connection *conn, const char *SID, const char *message, ...) @@ -153,24 +153,24 @@ length = strlen(buf); switch (conn->type) { case CT_CLIENT : -// printf("vvv send2(%*s", length, buf); +// PD("vvv send2(%*s", length, buf); ecore_con_client_send(conn->conn.client.client, strndup(buf, length), length); ecore_con_client_flush(conn->conn.client.client); break; case CT_SERVER : -// printf("^^^ send2(%*s", length, buf); +// PD("^^^ send2(%*s", length, buf); ecore_con_server_send(conn->conn.server.server, strndup(buf, length), length); ecore_con_server_flush(conn->conn.server.server); break; default : - printf("send2() unable to send to partially bogus Connection object!\n"); + PE("send2() unable to send to partially bogus Connection object!"); break; } } else - printf("send2() unable to send to bogus Connection object!\n"); + PE("send2() unable to send to bogus Connection object!"); } static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, void *ev) @@ -180,7 +180,6 @@ static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, voi const char *command; char *ext; -//printf("parseStream(%s, \"%*s\")\n", conn->name, evSize, (char *) evData); if (NULL == conn->stream) conn->stream = eina_strbuf_new(); @@ -202,7 +201,6 @@ static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, voi if (ext) { streamParser func = eina_hash_find(conn->commands, command); -//printf("parseStream(%s>> %s\"\n", conn->name, command); // ext[0] = '\0'; // Need a callback if we can't find the command. @@ -211,7 +209,7 @@ static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, voi if (func) func(conn->pointer, conn, SID, (char *) command, ext + 1); else - printf("parseStream() No function found for command %s!\n", command); + PE("parseStream() No function found for command %s!", command); } } @@ -297,9 +295,9 @@ static Eina_Bool clientDel(void *data, int type, Ecore_Con_Event_Client_Del *ev) // The "- 1" is coz this server is still counted. clients = ecore_con_server_clients_get(conn->conn.server.server) - 1; if (0 == eina_list_count(clients)) - printf("No more clients for %s, exiting.\n", conn->name); + PI("No more clients for %s, exiting.", conn->name); else - printf("Some (%d) more clients for %s, exiting anyway.\n", eina_list_count(clients), conn->name); + PW("Some (%d) more clients for %s, exiting anyway.", eina_list_count(clients), conn->name); // TODO - the Connection free function should take care of all of this, and we should call it here. ish. eina_clist_remove(conn->conn.client.server); @@ -345,7 +343,7 @@ Connection *openArms(char *name, const char *address, int port, void *data, Ecor ecore_con_server_client_limit_set(server, -1, 0); // ecore_con_server_timeout_set(server, 10); // ecore_con_server_client_limit_set(server, 3, 0); - printf("ACTUALLY created the %s server %s:%d.\n", name, address, port); + PI("ACTUALLY created the %s server %s:%d.", name, address, port); } else { @@ -368,9 +366,9 @@ static Eina_Bool serverAdd(void *data, int type, Ecore_Con_Event_Server_Add *ev) conn->stage++; if (conn->name) - printf("serverAdd()^^^^^^^^^^^^^^^^^^^^^^^Connected to %s server.\n", conn->name); + PI("serverAdd()^^^^^^^^^^^^^^^^^^^^^^^Connected to %s server.", conn->name); else - printf("serverAdd()^^^^^^^^^^^^^^^^^^^^^^^Connected to UNKNOWN server.\n"); + PW("serverAdd()^^^^^^^^^^^^^^^^^^^^^^^Connected to UNKNOWN server."); // In case the server crashed, clear out any waiting data. if (conn->stream) @@ -421,18 +419,16 @@ static Eina_Bool _reachOutTimer(void *data) { // TODO - Seems Ecore_con now has trouble with my try first, then start method, so start first, then try. Fix this, or do something else. case -3 : - printf("Failed to connect to a %s server, starting our own.\n", conn->name); + PW("Failed to connect to a %s server, starting our own.", conn->name); conn->conn.server.serverHandle = ecore_exe_pipe_run(conn->conn.server.serverCommand, ECORE_EXE_NONE /*| ECORE_EXE_TERM_WITH_PARENT*/, conn); if (conn->conn.server.serverHandle) { conn->conn.server.pid = ecore_exe_pid_get(conn->conn.server.serverHandle); if (conn->conn.server.pid == -1) - fprintf(stderr, "Could not retrive the PID!\n"); - else - fprintf(stdout, "The child process has PID:%u\n", (unsigned int)conn->conn.server.pid); + PE("Could not retrive the PID!"); } else - fprintf(stderr, "Could not create server process %s!\n", conn->conn.server.serverCommand); + PE("Could not create server process %s!", conn->conn.server.serverCommand); // TODO - There's also the question of what to do if the connection failed. // Did the server crash, or was it just the connection? @@ -448,20 +444,20 @@ static Eina_Bool _reachOutTimer(void *data) case -1 : // Give the server some time to start up. // Check if the server is still running here, if not, reset stage to previous -3 (taking into account the increment at the end). if (conn->conn.server.pid) - printf("Waiting for %s server to start from command \"%s\"\n", conn->name, conn->conn.server.serverCommand); + PI("Waiting for %s server to start from command \"%s\"", conn->name, conn->conn.server.serverCommand); else conn->stage = -4; break; case 0 : - printf("Attempting to connect to the %s server %s:%d.\n", conn->name, conn->address, conn->port); + PI("Attempting to connect to the %s server %s:%d.", conn->name, conn->address, conn->port); // This should only return NULL if something goes wrong with the setup, // you wont know if the connection worked until you get the add callback, // or you get the del calback if it failed. if ((server = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, conn->address, conn->port, conn))) - printf("MAYBE connecting to the %s server %s:%d.\n", conn->name, conn->address, conn->port); + PD("MAYBE connecting to the %s server %s:%d.", conn->name, conn->address, conn->port); else - printf("FAILED to create the connection to the %s server %s:%d!\n", conn->name, conn->address, conn->port); + PE("FAILED to create the connection to the %s server %s:%d!", conn->name, conn->address, conn->port); conn->conn.server.server = server; break; -- cgit v1.1