pax_global_header00006660000000000000000000000064134641020330014506gustar00rootroot0000000000000052 comment=34784e0c90efb449378b05bdfbb72bfa0a3ee3f0 modern-syslog-1.2.0/000077500000000000000000000000001346410203300143105ustar00rootroot00000000000000modern-syslog-1.2.0/.gitignore000066400000000000000000000000231346410203300162730ustar00rootroot00000000000000build node_modules modern-syslog-1.2.0/.travis.yml000066400000000000000000000003511346410203300164200ustar00rootroot00000000000000language: node_js node_js: - '0.10' - '0.12' - '4' - '5' - '6' - '8' - '10' - '11' - '12' sudo: false addons: apt: sources: - ubuntu-toolchain-r-test packages: - g++-4.8 env: - "CXX=g++-4.8" modern-syslog-1.2.0/CHANGES.md000066400000000000000000000030371346410203300157050ustar00rootroot000000000000002019-05-06, Version 1.2.0 ========================= * Support node up to and including 12.x (Sam Roberts) * CI: remove sudo:false from .travis.yml (Matt Simerson) 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! modern-syslog-1.2.0/LICENSE000066400000000000000000000022531346410203300153170ustar00rootroot00000000000000Copyright (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. modern-syslog-1.2.0/Makefile000066400000000000000000000000331346410203300157440ustar00rootroot00000000000000rebuild: node-gyp rebuild modern-syslog-1.2.0/README.md000066400000000000000000000115271346410203300155750ustar00rootroot00000000000000# 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 modern-syslog-1.2.0/binding.gyp000066400000000000000000000003251346410203300164430ustar00rootroot00000000000000{ "targets": [ { "target_name": "core", "sources": [ "core.cc" ], "include_dirs" : [ " #include #include using v8::Function; using v8::Int32; using v8::Isolate; using v8::Local; 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() { if(message) syslog(priority, "%s", message); } void HandleOKCallback() { Nan::HandleScope scope; if(callback) callback->Call(0, NULL, async_resource); }; private: int priority; char* message; }; static char ident[1024]; // wrap: void openlog(const char *ident, int option, int facility); NAN_METHOD(OpenLog) { const Nan::Utf8String arg0(info[0]); Local arg1 = Nan::To(info[1]).ToLocalChecked(); Local arg2 = Nan::To(info[2]).ToLocalChecked(); // openlog() requires ident be statically allocated. size_t length = arg0.length(); if(length) { if(length > sizeof(ident)-1) length = sizeof(ident)-1; strncpy(ident, *arg0, length); } int option = arg1->Value(); int facility = arg2->Value(); openlog(ident, option, facility); return; } static char* dupBuf(const Local& 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& arg) { const Nan::Utf8String str(arg); const char* mem = *str; size_t memsz = str.length(); char* s = new char[memsz + 1]; memcpy(s, mem, memsz); s[memsz] = 0; return s; } // wrap: void syslog(int priority, const char *format, ...); NAN_METHOD(SysLog) { Local arg0 = Nan::To(info[0]).ToLocalChecked(); int priority = arg0->Value(); char* message = NULL; Nan::Callback *callback = NULL; if(info[2]->IsFunction()) callback = new Nan::Callback(info[2].As()); if(node::Buffer::HasInstance(info[1])) { message = dupBuf(info[1]); } else { message = dupStr(info[1]); } if(message || callback) { Nan::AsyncQueueWorker(new Worker(callback, priority, message)); } return; } // wrap: int setlogmask(int mask); NAN_METHOD(SetLogMask) { Local arg0 = Nan::To(info[0]).ToLocalChecked(); int mask = arg0->Value(); int last = setlogmask(mask); info.GetReturnValue().Set(Nan::New(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 where = Nan::New(); #define DEFINE(N) Nan::Set(where, Nan::New(#N).ToLocalChecked(), Nan::New(N)) // option argument to openlog() is an OR of any of these: Nan::Set(target, Nan::New("option").ToLocalChecked(), where = Nan::New()); 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("facility").ToLocalChecked(), where = Nan::New()); 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("level").ToLocalChecked(), where = Nan::New()); 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); modern-syslog-1.2.0/index.js000066400000000000000000000066121346410203300157620ustar00rootroot00000000000000// 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; } modern-syslog-1.2.0/package.json000066400000000000000000000013211346410203300165730ustar00rootroot00000000000000{ "name": "modern-syslog", "version": "1.2.0", "description": "modern syslog - streaming, async, uses nan", "main": "index.js", "os": [ "!win32" ], "scripts": { "test": "tap test/test-*.js" }, "author": "Sam Roberts ", "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.13.2" }, "tags": [ "log", "logging", "nan", "syslog", "system" ] } modern-syslog-1.2.0/test/000077500000000000000000000000001346410203300152675ustar00rootroot00000000000000modern-syslog-1.2.0/test/test-compat.js000066400000000000000000000020731346410203300200670ustar00rootroot00000000000000// 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(); }); modern-syslog-1.2.0/test/test-core.js000066400000000000000000000025511346410203300175350ustar00rootroot00000000000000// 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() {}); modern-syslog-1.2.0/test/test-openlog.js000066400000000000000000000015211346410203300202440ustar00rootroot00000000000000// 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 tap = require('tap'); var assert = require('assert'); var syslog = require('../'); var o = syslog.option; var f = syslog.facility; tap.test(function(t) { t.doesNotThrow(function() { syslog.open('June', o.LOG_PERROR + o.LOG_PID, f.LOG_LOCAL1); syslog.upto('LOG_DEBUG'); t.comment('Expect on stderr a greeting to June with a PID:'); syslog.log('LOG_DEBUG', 'Hi, June', function() { syslog.open('Leonie', o.LOG_PERROR, f.LOG_LOCAL2); syslog.upto('LOG_DEBUG'); t.comment('Expect on stderr a greeting to Leonie without a PID:'); syslog.debug('Hi, %s', 'Leonie'); }); }, 'open and log'); t.end(); }); modern-syslog-1.2.0/test/test-setmask.js000066400000000000000000000042501346410203300202520ustar00rootroot00000000000000// 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 assert = require('assert'); var debug = require('debug')('modern-syslog:test'); var syslog = require('../'); var tap = require('tap'); var l = syslog.level; tap.test('setmask', function(t) { var mask0 = syslog.setmask(0x6); var mask1 = syslog.setmask(0x6); var mask2 = syslog.setmask(0x6); var mask3 = syslog.upto('LOG_DEBUG'); var mask4 = syslog.setmask(); t.equal(mask1, 0x6); t.equal(mask2, 0x6); t.equal(mask3, mask2); t.equal(mask4, syslog.logUpto('LOG_DEBUG')); t.equal(mask4, 0xff); t.end(); }); tap.test('logUpto', function(t) { var upto = syslog.logUpto; var mask; mask = upto('LOG_DEBUG'); t.equal(mask, 0xff); mask = upto('LOG_INFO'); t.equal(mask, 0x7f); t.assert((1 << l.LOG_CRIT) & mask); t.assert((1 << l.LOG_INFO) & mask); t.equal((1 << l.LOG_DEBUG) & mask, 0); mask = upto('LOG_NOTICE'); t.equal(mask, 0x3f); t.assert((1 << l.LOG_NOTICE) & mask); t.equal((1 << l.LOG_INFO) & mask, 0); t.equal((1 << l.LOG_DEBUG) & mask, 0); mask = upto('LOG_ALERT'); t.equal(mask, 0x03); t.assert((1 << l.LOG_EMERG) & mask); t.assert((1 << l.LOG_ALERT) & mask); t.equal((1 << l.LOG_CRIT) & mask, 0); t.equal((1 << l.LOG_DEBUG) & mask, 0); mask = upto('LOG_EMERG'); t.equal(mask, 0x01); t.assert((1 << l.LOG_EMERG) & mask); t.equal((1 << l.LOG_ALERT) & mask, 0); t.equal((1 << l.LOG_CRIT) & mask, 0); t.equal((1 << l.LOG_DEBUG) & mask, 0); t.end(); }); tap.test('upto', function(t) { syslog.upto(l.LOG_NOTICE); t.equal(syslog.curmask(), 0x3f); syslog.upto(l.LOG_CRIT); t.equal(syslog.curmask(), 0x07); syslog.upto(l.LOG_EMERG); t.equal(syslog.curmask(), 0x01); syslog.upto(l.LOG_DEBUG); t.equal(syslog.curmask(), 0xff); syslog.upto('LOG_NOTICE'); t.equal(syslog.curmask(), 0x3f); syslog.upto('LOG_CRIT'); t.equal(syslog.curmask(), 0x07); syslog.upto('LOG_EMERG'); t.equal(syslog.curmask(), 0x01); syslog.upto('LOG_DEBUG'); t.equal(syslog.curmask(), 0xff); t.end(); }); modern-syslog-1.2.0/test/test-stream.js000066400000000000000000000025771346410203300201100ustar00rootroot00000000000000// 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 assert = require('assert'); var fmt = require('util').format; var syslog = require('../'); var tap = require('tap'); var l = syslog.level; // Patch out the core syslog() so we can verify its arguments. function onLog(callback) { syslog.callback = function() { callback.apply(null, arguments); syslog.callback = null; }; } syslog.core.syslog = function() { if (syslog.callback) { syslog.callback.apply(null, arguments); return; } }; function test(level, facility) { tap.test(fmt('level=%s facility=%s', level, facility), function(t) { var strm = new syslog.Stream(level, facility); var _level = syslog.toLevel(level); var _facility = syslog.toFacility(facility); var _priority = _level | _facility; t.plan(2); onLog(function(priority, msg) { t.equal(priority, _priority, 'priority'); t.equal(String(msg), 'hello', 'message'); }); strm.end('hello'); strm.once('finish', function() { t.end(); }); }); } test(l.LOG_DEBUG); test(l.LOG_CRIT); test('LOG_CRIT'); test('LOG_CRIT', syslog.facility.LOG_LOCAL0); test('LOG_CRIT', 'LOG_LOCAL7'); test(l.LOG_INFO, syslog.facility.LOG_LOCAL6); test('LOG_EMERG', 'LOG_USER'); modern-syslog-1.2.0/test/test-syslog.js000066400000000000000000000043521346410203300201260ustar00rootroot00000000000000// 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 assert = require('assert'); var fmt = require('util').format; var syslog = require('../'); var tap = require('tap'); var l = syslog.level; function h(n) { return '0x' + n.toString(16); } var currentMask; function setmask(mask) { tap.test(fmt('set mask to %j', mask), function(t) { var last = syslog.setmask(mask); var now = syslog.setmask(mask); t.comment('set mask: was %s, set %s, now %s', h(last), h(mask), h(now)); currentMask = fmt('mask=%s', h(now)); if (mask === 0) { t.equal(last, now); } else { t.equal(mask, now); } t.end(); }); } var count = 0; function expect(l, m) { tap.test(fmt('log at %j msg %s', l, m), function(t) { var prefix = fmt('%s index %d level %s EXPECTED: (%s) ', currentMask, ++count, l, Buffer.isBuffer(m) ? 'buf' : 'str'); if (Buffer.isBuffer(m)) { m = Buffer(prefix + m); } else { m = prefix + m; } syslog.log(l, m, function() { t.end(); }); }); } function masked(l, m) { tap.test(fmt('masked at %j msg %s', l, m), function(t) { var m = fmt('%s level %s NOT EXPECTED: ', currentMask, l, m); syslog.log(l, m, function() { t.end(); }); }); } setmask(0xff); expect('LOG_CRIT', 'message'); expect('LOG_CRIT', Buffer('message')); expect(l.LOG_CRIT, 'message'); expect(l.LOG_CRIT, Buffer('message')); expect(l.LOG_DEBUG, 'debug'); setmask(syslog.logUpto('LOG_INFO')); expect(l.LOG_NOTICE, 'should see'); expect(l.LOG_INFO, 'should see'); masked(l.LOG_DEBUG, 'should not see'); setmask(syslog.logMask('LOG_INFO')); masked(l.LOG_NOTICE, 'should see'); expect(l.LOG_INFO, 'should see'); masked(l.LOG_DEBUG, 'should not see'); tap.test('MANUAL VERIFICATION ABOVE REQUIRED', function(t) { t.pass('test logs sent to syslog'); t.comment('%d log messages should be in syslog, looking like:', count); t.comment(' ... index 1 level (?) EXPECTED...'); t.comment(' ... index %d level (?) EXPECTED...', count); t.comment('And the indices should be ordered and consecutive'); t.end(); }); return