Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: master
...
compare: master
Checking mergeability… Don’t worry, you can still create the pull request.
  • 8 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
6 Emakefile
@@ -1,6 +0,0 @@
-{["src/*"],
- [{i, "include"},
- {outdir, "ebin"},
- debug_info]
-}.
-
View
44 Makefile
@@ -1,36 +1,26 @@
+REBAR=./rebar
-ERL=erl
-APP=syslog
+all: deps compile
-CC=gcc
+compile:
+ @$(REBAR) compile
-#Mac OS X: use "-m64" for a 64-bit erlang
-ARCH=-m64
+deps:
+ @$(REBAR) get-deps
-# By default, use the system crypt(3), which is DES only
-FLAGS=$(ARCH) -O3 -fPIC -shared
+clean:
+ @$(REBAR) clean
-# Linux
-#FLAGS=-fPIC -shared -lcrypt
+generate:
+ @$(REBAR) generate -f
-ERL_ROOT=/usr/local/lib/erlang
-CFLAGS=-g -Wall
+distclean: clean
+ @$(REBAR) delete-deps
+test: all
+ @$(REBAR) skip_deps=true eunit
-all: dir erl nif
-
-dir:
- -@mkdir -p priv ebin
-
-erl:
- @$(ERL) -noinput +B \
- -eval 'case make:all() of up_to_date -> halt(0); error -> halt(1) end.'
-
-nif:
- (cd c_src && \
- $(CC) -g -Wall $(FLAGS) -o ../priv/$(APP).so \
- $(APP).c -I $(ERL_ROOT)/usr/include/ )
-
-clean:
- @rm -fv ebin/*.beam priv/$(APP).so c_src/*.a c_src/*.o
+docs: deps
+ @$(REBAR) skip_deps=true doc
+.PHONY: deps test
View
27 README.markdown
@@ -1,18 +1,37 @@
A small nif to write to the local syslog daemon inspired by the project [JacobVorreuter/erlang_syslog](http://github.com/JacobVorreuter/erlang_syslog). Patches wanted.
+# Installation
+ $ git clone git://github.com/klyr/syslognif.git
+ $ cd syslognif
+ $ make
+
# TODO
- * openlog options
* tests
# Usage
Easier than you think:
- $ erl -pa /path/to/syslognif/ebin
- 1> syslog:open("foo").
+ $ erl -pa ebin
+ 1> syslog:open("foo", [pid, cons], local0).
ok
- 2> syslog:write(3, "This is a dead parrot!").
+ 2> syslog:write(err, "This is a dead parrot!").
ok
3> syslog:close().
ok
+
+
+# Syslog options
+
+pid, cons, odelay, ndelay, nowait, perror
+
+# Facilities
+
+kern, user, mail, daemon, auth, syslog, lpr, news, uucp, cron, authpriv, ftp, local0-7
+
+# Priorities
+
+emerge, alert, crit, err, warning, notice, info, debug
+
+For more information about these options see syslog(3) man page.
View
22 c_src/syslog.c
@@ -35,41 +35,41 @@ THE SOFTWARE.
const char ident[MAXBUFLEN];
-static ERL_NIF_TERM nif_open(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
+static ERL_NIF_TERM nif_openlog(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
int option;
int facility;
- if ( (enif_get_string(env, argv[0], (char *)ident, sizeof(ident), ERL_NIF_LATIN1) < 1) ||
- !enif_get_int(env, argv[1], &option) ||
- !enif_get_int(env, argv[2], &facility)) {
+ if ((enif_get_string(env, argv[0], (char *)ident, sizeof(ident), ERL_NIF_LATIN1) < 1) ||
+ !enif_get_int(env, argv[1], &option) ||
+ !enif_get_int(env, argv[2], &facility)) {
return enif_make_badarg(env);
}
openlog(ident, option, facility);
return enif_make_atom(env, "ok");
}
-static ERL_NIF_TERM nif_write(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
+static ERL_NIF_TERM nif_syslog(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
char message[MAXBUFLEN];
int log_level;
if (!enif_get_int(env, argv[0], &log_level)) {
return enif_make_badarg(env);
}
- if (enif_get_string(env, argv[1], message, sizeof(message), ERL_NIF_LATIN1) < 1) {
+ if (enif_get_string(env, argv[1], message, sizeof(message), ERL_NIF_LATIN1) == 0) {
return enif_make_badarg(env);
}
+ message[MAXBUFLEN - 1] = '\0';
syslog(log_level, "%s", message);
return enif_make_atom(env, "ok");
}
-static ERL_NIF_TERM nif_close(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
+static ERL_NIF_TERM nif_closelog(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
closelog();
return enif_make_atom(env, "ok");
}
static ErlNifFunc nif_funcs[] = {
- {"open", 3, nif_open},
- {"write", 2, nif_write},
- {"close", 0, nif_close}
+ {"openlog", 3, nif_openlog},
+ {"syslog", 2, nif_syslog},
+ {"closelog", 0, nif_closelog}
};
ERL_NIF_INIT(syslog, nif_funcs, NULL, NULL, NULL, NULL)
-
View
BIN  rebar
Binary file not shown
View
3  rebar.config
@@ -0,0 +1,3 @@
+{port_specs, [{"priv/syslog.so", ["c_src/syslog.c"]}]}.
+
+{clean_files, ["c_src/*.a", "c_src/*.o", "priv"]}.
View
3  src/syslog.app.src
@@ -0,0 +1,3 @@
+{application, syslog,
+ [{description, "NIF implementation of syslog functions"},
+ {vsn, "0.0.1"}]}.
View
27 src/syslog.erl
@@ -22,26 +22,33 @@
%% OTHER DEALINGS IN THE SOFTWARE.
-module(syslog).
-export([open/1, open/3, write/2, close/0,
+ openlog/3, syslog/2, closelog/0,
option/1, facility/1, level/1]).
-on_load(on_load/0).
on_load() ->
- Lib = filename:join([
- filename:dirname(code:which(?MODULE)),
- "..",
- "priv",
- ?MODULE
- ]),
+ Lib = case code:priv_dir(?MODULE) of
+ Path when is_list(Path) -> filename:join([Path, ?MODULE]);
+ _ -> filename:join([filename:dirname(code:which(?MODULE)),
+ "..", "priv", ?MODULE])
+ end,
erlang:load_nif(Lib, 0).
open(Ident) ->
- open(Ident, option(pid) bxor option(cons), level(info)).
+ openlog(Ident, option(pid) bxor option(cons), facility(user)).
-open(_,_,_) -> erlang:error(not_implemented).
+open(Ident, Options, Facility) when is_list(Options) ->
+ Opts = lists:foldl(fun(Opt, Acc) -> Acc bxor option(Opt) end, 0, Options),
+ openlog(Ident, Opts, facility(Facility)).
-write(_,_) -> erlang:error(not_implemented).
+write(Level, Str) ->
+ syslog(level(Level), Str).
-close() -> erlang:error(not_implemented).
+close() -> closelog().
+
+openlog(_,_,_) -> erlang:error(not_implemented).
+closelog() -> erlang:error(not_implemented).
+syslog(_,_) -> erlang:error(not_implemented).
% options for openlog()

No commit comments for this range

Something went wrong with that request. Please try again.