Skip to content

Commit

Permalink
Support 0.12/io.js using nan
Browse files Browse the repository at this point in the history
  • Loading branch information
remixz committed Feb 5, 2015
1 parent 0e7bb05 commit d64ddc1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
5 changes: 4 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"targets": [ {
"target_name": "syslog",
"sources": [ "src/syslog.cc" ]
"sources": [ "src/syslog.cc" ],
"include_dirs": [
"<!(node -e \"require('nan')\")"
]
} ]
}
45 changes: 23 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
{
"name": "bunyan-syslog",
"description": "Syslog Stream for Bunyan",
"version": "0.2.2",
"author": "Mark Cavage",
"main": "./lib/index.js",
"repository": {
"type": "git",
"url": "git://github.com/mcavage/node-bunyan-syslog.git"
},
"dependencies": {
"assert-plus": "0.1.4"
},
"devDependencies": {
"bunyan": "0.21.4",
"tap": "0.4.4"
},
"scripts": {
"test": "tap test"
},
"engines": {
"node": ">=0.8"
}
"name": "bunyan-syslog",
"description": "Syslog Stream for Bunyan",
"version": "0.2.2",
"author": "Mark Cavage",
"main": "./lib/index.js",
"repository": {
"type": "git",
"url": "git://github.com/mcavage/node-bunyan-syslog.git"
},
"dependencies": {
"assert-plus": "0.1.4",
"nan": "^1.6.1"
},
"devDependencies": {
"bunyan": "0.21.4",
"tap": "0.4.4"
},
"scripts": {
"test": "tap test"
},
"engines": {
"node": ">=0.8"
}
}
36 changes: 16 additions & 20 deletions src/syslog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

#include <node.h>
#include <v8.h>
#include <nan.h>

using namespace v8;

#define RETURN_EXCEPTION(MSG) \
return ThrowException(Exception::Error(String::New(MSG)))
NanThrowError(MSG)

#define RETURN_ARGS_EXCEPTION(MSG) \
return ThrowException(Exception::TypeError(String::New(MSG)))
NanThrowError(MSG)

#define RETURN_ERRNO_EXCEPTION(RC, API, MSG) \
return ThrowException(node::ErrnoException(RC, API, MSG))
NanThrowError(node::ErrnoException(RC, API, MSG))

#define RETURN_OOM_EXCEPTION() \
RETURN_ERRNO_EXCEPTION(ENOMEM, "malloc", strerror(ENOMEM))
Expand Down Expand Up @@ -53,52 +54,47 @@ using namespace v8;

///--- API


Handle<Value> Open(const Arguments& args) {
HandleScope scope;
NAN_METHOD(Open) {
NanScope();

REQUIRE_STRING_ARG(args, 0, ident);
REQUIRE_INT_ARG(args, 1, logopt);
REQUIRE_INT_ARG(args, 2, facility);

openlog(strdup(*ident), logopt, facility);

return (Undefined());
NanReturnUndefined();
}


Handle<Value> Log(const Arguments& args) {
HandleScope scope;
NAN_METHOD(Log) {
NanScope();

REQUIRE_INT_ARG(args, 0, priority);
REQUIRE_STRING_ARG(args, 1, message);

syslog(priority, "%s", *message);

return (Undefined());
NanReturnUndefined();
}


Handle<Value> Close(const Arguments& args) {
HandleScope scope;
NAN_METHOD(Close) {
NanScope();

closelog();

return (Undefined());
NanReturnUndefined();
}


Handle<Value> Mask(const Arguments& args) {
HandleScope scope;
NAN_METHOD(Mask) {
NanEscapableScope();

REQUIRE_INT_ARG(args, 0, maskpri);

int mask = setlogmask(LOG_UPTO(maskpri));

return (scope.Close(Integer::New(mask)));
NanReturnValue(NanEscapeScope(NanNew<Integer>(mask)));
}


void init(Handle<Object> target) {
NODE_SET_METHOD(target, "openlog", Open);
NODE_SET_METHOD(target, "syslog", Log);
Expand Down

0 comments on commit d64ddc1

Please sign in to comment.