summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anylike.org>2009-12-25 09:33:35 +0000
committerChristian Pointner <equinox@anylike.org>2009-12-25 09:33:35 +0000
commit52dce0bb3a42a5cd6a5a84b10a65fe1f140fb9bc (patch)
tree5da04ee87c2912b34d335a5b1ae18fd0d619de71
parentadded logging (diff)
added lua library for logging
-rw-r--r--src/Makefile1
-rw-r--r--src/anylike.c2
-rw-r--r--src/l_log.c91
-rw-r--r--src/l_log.h34
-rw-r--r--src/main_loop.lua6
5 files changed, 133 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile
index 2eed24b..1d63ea1 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -33,6 +33,7 @@ EXECUTABLE := anylike
# sysexec.o \
OBJ := log.o \
+ l_log.o \
options.o \
string_list.o \
anylike.o
diff --git a/src/anylike.c b/src/anylike.c
index f7be9c0..5ca18cb 100644
--- a/src/anylike.c
+++ b/src/anylike.c
@@ -31,12 +31,14 @@
#include "datatypes.h"
#include "options.h"
#include "log.h"
+#include "l_log.h"
int main_loop(options_t* opt)
{
lua_State *L;
L = lua_open();
luaopen_base(L);
+ luaopen_log(L);
log_printf(NOTICE, "will now start main_loop.lua");
diff --git a/src/l_log.c b/src/l_log.c
new file mode 100644
index 0000000..fa587b1
--- /dev/null
+++ b/src/l_log.c
@@ -0,0 +1,91 @@
+/*
+ * anylike
+ *
+ * anylike is a ...
+ *
+ *
+ * Copyright (C) 2009-2010 Markus Grueneis <gimpf@anylike.org>
+ * Christian Pointner <equinox@anylike.org>
+ *
+ * This file is part of anylike.
+ *
+ * anylike is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * anylike is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with anylike. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <lua50/lua.h>
+
+#include <stdlib.h>
+#include "log.h"
+
+#include "l_log.h"
+
+
+/* void log_init(); */
+/* void log_close(); */
+/* void update_max_prio(); */
+/* int log_add_target(const char* conf); */
+/* void log_printf(log_prio_t prio, const char* fmt, ...); */
+/* void log_print_hex_dump(log_prio_t prio, const u_int8_t* buf, u_int32_t len); */
+
+static int l_log_init(lua_State *L)
+{
+ log_init();
+ return 0;
+}
+
+static int l_log_close(lua_State *L)
+{
+ log_close();
+ return 0;
+}
+
+static int l_log_print(lua_State *L)
+{
+ const char* prio_str = luaL_checklstring(L,1,NULL);
+ log_prio_t prio;
+ if(prio_str) {
+ if(!strncmp("ERROR", prio_str, 6))
+ prio = ERROR;
+ else if(!strncmp("WARNING", prio_str, 6))
+ prio = WARNING;
+ else if(!strncmp("NOTICE", prio_str, 6))
+ prio = NOTICE;
+ else if(!strncmp("INFO", prio_str, 6))
+ prio = INFO;
+ else if(!strncmp("DEBUG", prio_str, 6))
+ prio = DEBUG;
+ else {
+// this is an error ...
+ }
+ }
+ else {
+// thist is an error as well
+ }
+
+ log_printf(prio, "lua: %s", luaL_checklstring(L, 2, NULL));
+ return 0;
+}
+
+static const struct luaL_reg loglib [] = {
+ { "init", l_log_init },
+ { "close", l_log_close },
+ { "print", l_log_print },
+ { NULL, NULL }
+};
+
+
+LUALIB_API int luaopen_log (lua_State *L) {
+ luaL_openlib(L, "log", loglib, 0);
+ return 1;
+}
diff --git a/src/l_log.h b/src/l_log.h
new file mode 100644
index 0000000..97d23c5
--- /dev/null
+++ b/src/l_log.h
@@ -0,0 +1,34 @@
+/*
+ * anylike
+ *
+ * anylike is a ...
+ *
+ *
+ * Copyright (C) 2009-2010 Markus Grueneis <gimpf@anylike.org>
+ * Christian Pointner <equinox@anylike.org>
+ *
+ * This file is part of anylike.
+ *
+ * anylike is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * anylike is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with anylike. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ANYLIKE_l_log_h_INCLUDED
+#define ANYLIKE_l_log_h_INCLUDED
+
+#include <lua50/lua.h>
+#include <lua50/lauxlib.h>
+
+LUALIB_API int luaopen_log (lua_State *L);
+
+#endif
diff --git a/src/main_loop.lua b/src/main_loop.lua
index 64963bb..e3dfb71 100644
--- a/src/main_loop.lua
+++ b/src/main_loop.lua
@@ -23,4 +23,8 @@
-- along with anylike. If not, see <http://www.gnu.org/licenses/>.
--
-print("lua: main_loop started");
+log.print("NOTICE", "main_loop started");
+
+log.print("DEBUG", "yet anoter message");
+
+log.print("ERROR", "this is an error"); \ No newline at end of file