-
Notifications
You must be signed in to change notification settings - Fork 1
/
lsyslog.c
153 lines (140 loc) · 3.72 KB
/
lsyslog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
** LuaSystemLog
** Copyright DarkGod 2007
**
*/
#include <syslog.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
static int lsyslog_open(lua_State *L)
{
const char *ident = luaL_checkstring(L, 1);
int facility = luaL_checkinteger(L, 2);
openlog(ident, LOG_PID, facility);
return 0;
}
static int lsyslog_log(lua_State *L)
{
int level = luaL_checkinteger(L, 1);
const char *line = luaL_checkstring(L, 2);
syslog(level, "%s", line);
return 0;
}
static int lsyslog_close(lua_State *L)
{
closelog();
return 0;
}
/*
** Assumes the table is on top of the stack.
*/
static void set_info (lua_State *L)
{
lua_pushliteral (L, "_COPYRIGHT");
lua_pushliteral (L, "Copyright (C) 2007 DarkGod");
lua_settable (L, -3);
lua_pushliteral (L, "_DESCRIPTION");
lua_pushliteral (L, "LuaSyslog allows to use LuaLogging with an unix Syslog daemon");
lua_settable (L, -3);
lua_pushliteral (L, "_VERSION");
lua_pushliteral (L, "LuaSyslog 1.0.0");
lua_settable (L, -3);
lua_pushliteral(L, "FACILITY_AUTH");
lua_pushnumber(L, LOG_AUTH);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_AUTHPRIV");
lua_pushnumber(L, LOG_AUTHPRIV);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_CRON");
lua_pushnumber(L, LOG_CRON);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_DAEMON");
lua_pushnumber(L, LOG_DAEMON);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_FTP");
lua_pushnumber(L, LOG_FTP);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_KERN");
lua_pushnumber(L, LOG_KERN);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_LPR");
lua_pushnumber(L, LOG_LPR);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_MAIL");
lua_pushnumber(L, LOG_MAIL);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_NEWS");
lua_pushnumber(L, LOG_NEWS);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_SYSLOG");
lua_pushnumber(L, LOG_SYSLOG);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_USER");
lua_pushnumber(L, LOG_USER);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_UUCP");
lua_pushnumber(L, LOG_UUCP);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_LOCAL0");
lua_pushnumber(L, LOG_LOCAL0);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_LOCAL1");
lua_pushnumber(L, LOG_LOCAL1);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_LOCAL2");
lua_pushnumber(L, LOG_LOCAL2);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_LOCAL3");
lua_pushnumber(L, LOG_LOCAL3);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_LOCAL4");
lua_pushnumber(L, LOG_LOCAL4);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_LOCAL5");
lua_pushnumber(L, LOG_LOCAL5);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_LOCAL6");
lua_pushnumber(L, LOG_LOCAL6);
lua_settable(L, -3);
lua_pushliteral(L, "FACILITY_LOCAL7");
lua_pushnumber(L, LOG_LOCAL7);
lua_settable(L, -3);
lua_pushliteral(L, "LOG_EMERG");
lua_pushnumber(L, LOG_EMERG);
lua_settable(L, -3);
lua_pushliteral(L, "LOG_ALERT");
lua_pushnumber(L, LOG_ALERT);
lua_settable(L, -3);
lua_pushliteral(L, "LOG_CRIT");
lua_pushnumber(L, LOG_CRIT);
lua_settable(L, -3);
lua_pushliteral(L, "LOG_ERR");
lua_pushnumber(L, LOG_ERR);
lua_settable(L, -3);
lua_pushliteral(L, "LOG_WARNING");
lua_pushnumber(L, LOG_WARNING);
lua_settable(L, -3);
lua_pushliteral(L, "LOG_NOTICE");
lua_pushnumber(L, LOG_NOTICE);
lua_settable(L, -3);
lua_pushliteral(L, "LOG_INFO");
lua_pushnumber(L, LOG_INFO);
lua_settable(L, -3);
lua_pushliteral(L, "LOG_DEBUG");
lua_pushnumber(L, LOG_DEBUG);
lua_settable(L, -3);
}
static const struct luaL_reg lsysloglib[] =
{
{"open", lsyslog_open},
{"close", lsyslog_close},
{"log", lsyslog_log},
{NULL, NULL},
};
int luaopen_lsyslog(lua_State *L)
{
luaL_openlib(L, "lsyslog", lsysloglib, 0);
set_info(L);
return 1;
}