Commit e1e6068f authored by Xavier Guimard's avatar Xavier Guimard

New upstream version 1.1.4

parents
build
node_modules
language: node_js
node_js:
- '0.10'
- '0.12'
- '4'
- '5'
- '6'
sudo: false
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
env:
- "CXX=g++-4.8"
2016-09-30, Version 1.1.4
=========================
* package: test against node 6.x in travis (Sam Roberts)
* Check that cb is a function, not non-empty (Sam Roberts)
2016-03-23, Version 1.1.3
=========================
* update repo information in package.json (Ryan Graham)
* update copyrights (Ryan Graham)
* ci: remove iojs, add node-v5 (Ryan Graham)
* Refer to licenses with a link (Sam Roberts)
2015-10-16, Version 1.1.2
=========================
* define LOG_PERROR if not defined by platform (Ryan Graham)
* Use strongloop conventions for licensing (Sam Roberts)
2015-09-18, Version 1.1.1
=========================
* fix toFacility() so it preserves numbers (Ryan Graham)
* test: toLevel() and toFacility() (Ryan Graham)
* travis: replace iojs-head with node-v4 (Ryan Graham)
* add travis config (Ryan Graham)
2015-09-02, Version 1.1.0
=========================
* compatiblity: expose LOG_ properties globally (Sam Roberts)
2015-08-21, Version 1.0.3
=========================
* upgrade to nan@2 (Ryan Graham)
* test: make test output more TAP friendly (Ryan Graham)
2015-08-20, Version 1.0.2
=========================
* Package metadata for npmjs.org (Sam Roberts)
2015-08-20, Version 1.0.1
=========================
* Fix package name, its modern-syslog (Sam Roberts)
2015-08-20, Version 1.0.0
=========================
* First release!
Copyright (c) IBM Corp. 2015,2016. All Rights Reserved.
Node module: modern-syslog
This project is licensed under the MIT License, full text below.
--------
MIT license
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
rebuild:
node-gyp rebuild
# modern syslog - streaming, async, native, uses nan
This is the only syslog library that:
- Uses native bindings to the libc syslog API.
- Is async, because the libc APIs can block on localhost IPC under load, but
that shouldn't block your app.
- Can be used as a stream.
- Has formatted log functions.
- Uses nan, so supports node and io.js, and will continue to do so.
- Is API compatible with [node-syslog][], from which I gathered inspiration
and owe thanks.
Default mask depends on system.
## Installation
npm install --save modern-syslog
## API
For detailed descriptions of the core functions, see [man 3
syslog](http://man7.org/linux/man-pages/man3/syslog.3.html).
Note that syslog functions cannot fail, and neither throw errors, nor callback
with errors. This is consistent with the core functions, which do not have error
return values.
### log(priority, msg, callback)
- `priority` {String|Number} OR of a level, and optionally, a facility.
- `msg` {String|Buffer} Message to log.
- `callback` {Function} Called after message is logged (no arguments).
`priority` can be a String, in which case it will be looked up in
`syslog.level`. It can also be a Number, in which case it is expected to be
a numeric value, such as `syslog.level.LOG_INFO`, optionally ORed with a
a numeric facility, such as `syslog.facility.LOG_LOCAL2`.
See below for formatted version of `log()`.
### emerg(fmt, ...)
### alert(fmt, ...)
### crit(fmt, ...)
### error(fmt, ...)
### err(fmt, ...)
### warn(fmt, ...)
### warning(fmt, ...)
### note(fmt, ...)
### notice(fmt, ...)
### info(fmt, ...)
### debug(fmt, ...)
- `fmt` {String} Arguments are formatted as `msg`, and passed to `log()`.
Convenience functions, log level is pre-defined, facility uses default, either
system default or that provided to `open()`, and message is formatted with
`util.format()`.
### new Stream(level, [facility])
- `level` {String|Number} Level to log at.
- `facility` {String|Number} Facility to log with, optional.
Returns a writeable stream that logs all messages at the specified level and
facility.
### open(ident, option, facility)
- `ident` {String} Prepended to every message, usually program name.
- `option` {Number} OR of flags from `syslog.options`.
- `facility` {String|Number} Default facility to be used by `log()`.
Set up defaults for log.
Calling `open()` is optional, all arguments are provided with defaults, though
the defaults depend on the system (see man page).
### close()
Close the socket to the syslog system.
Calling `close()` is optional, the socket is closed automatically by the
system on exit.
### upto(level)
- `level` {String|Number} Level to log up to.
Log all levels upto and including `level`.
### setmask(mask)
- `mask` {Number} OR of levels that should be logged.
Not convenient to use but part of the low-level syslog API. See syslog man page
for details, and consider using `upto()` for most common use-cases.
### curmask()
Returns current log mask, see `setmask()`.
### setMask(...)
Avoid this, its for backwards compatibility with [node-syslog][].
### init(...)
Avoid this, its for backwards compatibility with [node-syslog][].
## Properties
Syslog properties are defined as a bi-directional map from String to Number, and
from Number to String, so:
- `syslog.level.LOG_DEBUG`: `7`, the numeric value of `LOG_DEBUG`
- `syslog.level[7]`: `'LOG_DEBUG'`, string value of level `7`
### syslog.level
Levels are listed from highest priority, to lowest:
- `LOG_EMERG`: System is unusable.
- `LOG_ALERT`: Action must be taken immediately.
- `LOG_CRIT`: Critical condition.
- `LOG_ERR`: Error condition.
- `LOG_WARNING`: Warning condition.
- `LOG_NOTICE`: Normal, but significant, condition.
- `LOG_INFO`: Informational message.
- `LOG_DEBUG`: Debug-level message.
### syslog.option
Object of properties:
- `LOG_CONS`: Log to console if there is error logging to syslog.
- `LOG_PERROR`: Log to stderr as well as syslog. (no-op on Solaris)
- `LOG_PID`: Log process' PID with each message.
These are unlikely to be useful, but are provided for completeness:
- `LOG_NDELAY`: Open the connection immediately (normally, the connection is
opened when the first message is logged).
- `LOG_ODELAY`: The converse of `LOG_NDELAY`; opening of the connection is
delayed until the first message is logged (this is the default and need not be
specified).
- `LOG_NOWAIT`: Archaic option that doesn't do anything on contemporary systems,
but is provided for backwards compatibility.
### syslog.facility
- `LOG_AUTH`
- `LOG_AUTHPRIV` (not defined on all systems)
- `LOG_CRON`
- `LOG_DAEMON`
- `LOG_FTP` (not defined on all systems)
- `LOG_KERN`
- `LOG_LOCAL0`
- `LOG_LOCAL1`
- `LOG_LOCAL2`
- `LOG_LOCAL3`
- `LOG_LOCAL4`
- `LOG_LOCAL5`
- `LOG_LOCAL6`
- `LOG_LOCAL7`
- `LOG_LPR`
- `LOG_MAIL`
- `LOG_NEWS`
- `LOG_SYSLOG`
- `LOG_USER`
- `LOG_UUCP`
[node-syslog]: https://www.npmjs.com/package/node-syslog
{
"targets": [
{
"target_name": "core",
"sources": [
"core.cc"
],
"include_dirs" : [
"<!(node -e \"require('nan')\")"
],
"cflags": ["-g"]
}
]
}
#include <node.h>
#include <nan.h>
#include <syslog.h>
using v8::Function;
using v8::FunctionTemplate;
using v8::Handle;
using v8::Local;
using v8::Null;
using v8::Number;
using v8::Object;
using v8::String;
using v8::Value;
namespace {
class Worker: public Nan::AsyncWorker {
public:
Worker(Nan::Callback *callback, int priority, char* message)
: Nan::AsyncWorker(callback), priority(priority), message(message) {
}
~Worker() {
delete[] message;
}
void Execute() {
syslog(priority, "%s", message);
}
void HandleOKCallback() {
Nan::HandleScope scope;
if(callback)
callback->Call(0, NULL);
};
private:
int priority;
char* message;
};
static char ident[1024];
// wrap: void openlog(const char *ident, int option, int facility);
NAN_METHOD(OpenLog) {
// openlog requires ident be statically allocated. Write doesn't guarantee
// NULL-termination, so preserve last byte as NULL.
info[0]->ToString()->WriteUtf8(ident, sizeof(ident)-1);
int option = info[1]->Int32Value();
int facility = info[2]->Int32Value();
openlog(ident, option, facility);
return;
}
static char* dupBuf(const Handle<Value>& arg) {
const char* mem = node::Buffer::Data(arg);
size_t memsz = node::Buffer::Length(arg);
char* s = new char[memsz + 1];
memcpy(s, mem, memsz);
s[memsz] = 0;
return s;
}
static char* dupStr(const Local<String>& m) {
if(m.IsEmpty())
return NULL;
// Exact calculation of UTF length involves double traversal. Avoid this
// because we know UTF8 expansion is < 4 bytes out per byte in.
char* s = new char[m->Length() * 4];
m->WriteUtf8(s);
return s;
}
// wrap: void syslog(int priority, const char *format, ...);
NAN_METHOD(SysLog) {
int priority = info[0]->Int32Value();
char* message = NULL;
Nan::Callback *callback = NULL;
if (info[2]->IsFunction())
callback = new Nan::Callback(info[2].As<Function>());
if(node::Buffer::HasInstance(info[1])) {
message = dupBuf(info[1]);
} else {
message = dupStr(info[1]->ToString());
}
if (message) {
Nan::AsyncQueueWorker(new Worker(callback, priority, message));
} else if(callback) {
callback->Call(0, NULL);
delete callback;
}
return;
}
// wrap: int setlogmask(int mask);
NAN_METHOD(SetLogMask) {
int mask = info[0]->Int32Value();
int last = setlogmask(mask);
info.GetReturnValue().Set(Nan::New<Number>(last));
}
// wrap: void closelog(void);
NAN_METHOD(CloseLog) {
closelog();
return;
}
NAN_MODULE_INIT(Init) {
Nan::Export(target, "openlog", OpenLog);
Nan::Export(target, "syslog", SysLog);
Nan::Export(target, "setlogmask", SetLogMask);
Nan::Export(target, "closelog", CloseLog);
Local<Object> where = Nan::New<Object>();
#define DEFINE(N) Nan::Set(where, Nan::New<String>(#N).ToLocalChecked(), Nan::New<Number>(N))
// option argument to openlog() is an OR of any of these:
Nan::Set(target, Nan::New<String>("option").ToLocalChecked(), where = Nan::New<Object>());
DEFINE(LOG_CONS);
DEFINE(LOG_NDELAY);
DEFINE(LOG_ODELAY);
#ifndef LOG_PERROR
// not defined on Solaris but we want the exported object to be consistent
#define LOG_PERROR 0x0 // no-op
#endif
DEFINE(LOG_PERROR);
DEFINE(LOG_PID);
DEFINE(LOG_NOWAIT);
// facility argument to openlog() is any ONE of these:
Nan::Set(target, Nan::New<String>("facility").ToLocalChecked(), where = Nan::New<Object>());
DEFINE(LOG_AUTH);
#ifdef LOG_AUTHPRIV
DEFINE(LOG_AUTHPRIV);
#endif
DEFINE(LOG_CRON);
DEFINE(LOG_DAEMON);
#ifdef LOG_FTP
DEFINE(LOG_FTP);
#endif
DEFINE(LOG_KERN);
DEFINE(LOG_LOCAL0);
DEFINE(LOG_LOCAL1);
DEFINE(LOG_LOCAL2);
DEFINE(LOG_LOCAL3);
DEFINE(LOG_LOCAL4);
DEFINE(LOG_LOCAL5);
DEFINE(LOG_LOCAL6);
DEFINE(LOG_LOCAL7);
DEFINE(LOG_LPR);
DEFINE(LOG_MAIL);
DEFINE(LOG_NEWS);
DEFINE(LOG_SYSLOG);
DEFINE(LOG_USER);
DEFINE(LOG_UUCP);
// priority argument to syslog() is an OR of a facility and ONE log level:
Nan::Set(target, Nan::New<String>("level").ToLocalChecked(), where = Nan::New<Object>());
DEFINE(LOG_EMERG);
DEFINE(LOG_ALERT);
DEFINE(LOG_CRIT);
DEFINE(LOG_ERR);
DEFINE(LOG_WARNING);
DEFINE(LOG_NOTICE);
DEFINE(LOG_INFO);
DEFINE(LOG_DEBUG);
}
}
NODE_MODULE(core, Init);
// Copyright IBM Corp. 2015,2016. All Rights Reserved.
// Node module: modern-syslog
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
var Writable = require('stream').Writable;
var core = require('./build/Release/core.node');
var inherits = require('util').inherits;
var fmt = require('util').format;
// Direct access to the core binding
exports.core = core;
// Constants
exports.option = core.option;
exports.facility = core.facility;
exports.level = core.level;
// High-level API, remove the redundant 'log' from method names.
exports.version = require('./package.json').version;
exports.open = open;
exports.init = exports.open;
exports.log = log;
exports.upto = upto;
exports.curmask = curmask;
exports.setMask = setMask;
exports.close = core.closelog;
exports.Stream = Stream;
function open(ident, option, facility) {
// XXX(sam) would be nice to allow single strings for option
core.openlog(ident, option, toFacility(facility));
}
function log(level, msg, callback) {
core.syslog(toLevel(level), msg, callback);
}
function wrap(name, level) {
level = core.level[level];
exports[name] = function(msg) {
core.syslog(level, fmt.apply(null, arguments));
};
}
wrap('emerg', 'LOG_EMERG');
wrap('alert', 'LOG_ALERT');
wrap('crit', 'LOG_CRIT');
wrap('error', 'LOG_ERR');
wrap('err', 'LOG_ERR');
wrap('warn', 'LOG_WARNING');
wrap('warning', 'LOG_WARNING');
wrap('note', 'LOG_NOTICE');
wrap('notice', 'LOG_NOTICE');
wrap('info', 'LOG_INFO');
wrap('debug', 'LOG_DEBUG');
// Low-level API
exports.setmask = core.setlogmask;
exports.toLevel = toLevel;
exports.toFacility = toFacility;
exports.logMask = logMask;
exports.logUpto = logUpto;
// Invert constants, so its easy to look the string up by the value.
// Expose keys globally, for backwards compatibility with node-syslog.
function expose(obj) {
for (var key in obj) {
var val = obj[key];
exports[key] = val;
obj[val] = key;
}
}
expose(exports.option);
expose(exports.facility);
expose(exports.level);
// setlogmask() is too painful to use, most systems have a LOG_UPTO(level)
// macro, we'll just export upto() directly, its what most users will want.
function upto(level) {
return core.setlogmask(logUpto(level));
}
// Linux allows calling setmask(0) to get the current mask, but OS X does not,
// so make a curmask() to smooth this over.
function curmask() {
var cur = core.setlogmask(0);
core.setlogmask(cur);
return cur;
}
function setMask(level, upto) {
var mask;
if (upto)
mask = logUpto(level);
else
mask = logMask(level);
core.setlogmask(mask);
}
// Writable stream for syslog.
function Stream(level, facility) {
if (!(this instanceof Stream))
return new Stream(level, facility);
this.priority = toLevel(level) | toFacility(facility);
Writable.apply(this);
}
inherits(Stream, Writable);
Stream.prototype._write = function(chunk, encoding, callback) {
core.syslog(this.priority, chunk, callback);
};
// Low-level API
function toLevel(level) {
if (typeof level === 'string' && level in core.level)
return core.level[level];
return level;
}
function toFacility(facility) {
if (typeof facility === 'string' && facility in core.facility)
return core.facility[facility];
return facility;
}
function logMask(level) {
return 1 << toLevel(level);
}
function logUpto(level) {
return (1 << (toLevel(level) + 1)) - 1;
}
{
"name": "modern-syslog",
"version": "1.1.4",
"description": "modern syslog - streaming, async, uses nan",
"main": "index.js",
"os": [
"!win32"
],
"scripts": {
"test": "tap test/test-*.js"
},
"author": "Sam Roberts <rsam@ca.ibm.com>",
"homepage": "http://github.com/strongloop/modern-syslog",
"repository": {
"type": "git",
"url": "git@github.com:strongloop/modern-syslog.git"
},
"bugs": {
"url": "https://github.com/strongloop/modern-syslog/issues"
},
"license": "MIT",
"devDependencies": {
"debug": "^2.1.2",
"tap": "^1.3.2"
},
"dependencies": {
"nan": "^2.0.5"
},
"tags": [
"log",
"logging",
"nan",
"syslog",
"system"
]
}
// Copyright IBM Corp. 2015,2016. All Rights Reserved.
// Node module: modern-syslog
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var Syslog = require('../');
var assert = require('assert');
var tap = require('tap');
tap.test(function(t) {
t.doesNotThrow(function() {
Syslog.init("node-syslog-test", Syslog.LOG_PID | Syslog.LOG_ODELAY, Syslog.LOG_LOCAL0);
}, 'Syslog.init');
t.doesNotThrow(function() {
Syslog.log(Syslog.LOG_INFO, "news info log test");
}, 'Syslog.log/Syslog.LOG_INFO');
t.doesNotThrow(function() {
Syslog.log(Syslog.LOG_ERR, "news log error test");
}, 'Syslog.log/Syslog.LOG_ERR');
t.doesNotThrow(function() {
Syslog.log(Syslog.LOG_DEBUG, "Last log message as debug: " + new Date());
}, 'Syslog.log/Syslog.LOG_DEBUG');
t.doesNotThrow(function() {
Syslog.close();
}, 'Syslog.close');
t.equal(Syslog.LOG_KERN, Syslog.facility.LOG_KERN);
t.equal(Syslog.LOG_PID, Syslog.option.LOG_PID);
t.equal(Syslog.LOG_EMERG, Syslog.level.LOG_EMERG);
t.end();
});
// Copyright IBM Corp. 2015,2016. All Rights Reserved.
// Node module: modern-syslog
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var fmt = require('util').format;
var syslog = require('../');
var tap = require('tap');
tap.test('core properties exist', function(t) {
t.assert(syslog.core);
t.assert(syslog.core.openlog);
t.assert(syslog.core.syslog);
t.assert(syslog.core.setlogmask);
t.assert(syslog.core.closelog);
t.assert(syslog.core.option.LOG_PID);
t.assert(syslog.core.facility.LOG_LOCAL0);
t.assert(syslog.core.level.LOG_DEBUG);
t.end();
});
tap.test('low-level helpers', function(t) {
t.equal(syslog.toFacility(0), 0, 'toFacility preserves numbers');
t.equal(syslog.toLevel(0), 0, 'toLevel preserves numbers');
t.equal(syslog.toFacility('LOG_LOCAL0'), syslog.facility.LOG_LOCAL0,
'toFacility preserves numbers');
t.equal(syslog.toLevel('LOG_EMERG'), syslog.level.LOG_EMERG,
'toLevel preserves numbers');
t.end();
});
function accept(m) {
tap.test(fmt('core syslog accepts %j', m), function(t) {
t.plan(1);
syslog.core.syslog(syslog.core.level.LOG_DEBUG, m, function() {
t.assert(true, 'called back');
});
});
}
accept('string');
accept(Buffer('buffer'));
accept(undefined);
accept(null);
accept({some: 5});
accept(function fn() {});
// Copyright IBM Corp. 2015,2016. All Rights Reserved.