Skip to content

Commit

Permalink
#49 Release v0.3.2
Browse files Browse the repository at this point in the history
#50 Use ESLint for linting and style checking
Reviewed by: Patrick Mooney <[email protected]>
Approved by: Patrick Mooney <[email protected]>
  • Loading branch information
melloc committed Aug 27, 2018
1 parent 9bdb9eb commit c3daebf
Show file tree
Hide file tree
Showing 27 changed files with 770 additions and 91 deletions.
22 changes: 22 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"plugins": [ "joyent" ],
"extends": [
"eslint:recommended",
"plugin:joyent/style",
"plugin:joyent/lint"
],
"parserOptions": {
"ecmaVersion": 5,
"sourceType": "script",
"ecmaFeatures": {
}
},
"env": {
"node": true
},
"rules": {
// Style:
"func-style": [ "error", "declaration" ],
"multiline-comment-style": [ "error", "starred-block" ]
}
}
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/build
/coverage
/node
/node_modules
/tmp
build
/package-lock.json
*.log
docs/*.json
docs/*.html
cscope.in.out
cscope.po.out
cscope.out
npm-debug.log
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "deps/jsstyle"]
path = deps/jsstyle
url = git://github.com/davepacheco/jsstyle.git
url = https://github.com/joyent/jsstyle.git
[submodule "deps/javascriptlint"]
path = deps/javascriptlint
url = git://github.com/davepacheco/javascriptlint.git
url = https://github.com/joyent/javascriptlint.git
21 changes: 14 additions & 7 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
deps
tools
build
test
.gitmodules
.npmignore
*.log
/Makefile
/deps
/test
/tools
/.gitmodules
/.npmignore
/.eslintrc
/.travis.yml
/CONTRIBUTING.md
/build
/node
/coverage
/test.pid
*.tgz
Makefile
46 changes: 35 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#
# Copyright (c) 2013, Mark Cavage. All rights reserved.
# Copyright (c) 2018, Joyent, Inc.
#

#
# Tools
#
NPM := npm
NPM_EXEC := npm
TAP := ./node_modules/.bin/tap

ISTANBUL := node_modules/.bin/istanbul
FAUCET := node_modules/.bin/faucet

#
# Files
Expand All @@ -16,22 +17,45 @@ JSL_CONF_NODE = tools/jsl.node.conf
JSL_FILES_NODE = $(JS_FILES)
JSSTYLE_FILES = $(JS_FILES)
JSSTYLE_FLAGS = -f tools/jsstyle.conf
ESLINT_FILES = $(JS_FILES)
BUILD := node

CLEAN_FILES += ./node_modules build
ifeq ($(shell uname -s),SunOS)
NODE_PREBUILT_VERSION = v4.9.0
NODE_PREBUILT_TAG = zone
NODE_PREBUILT_IMAGE = 18b094b0-eb01-11e5-80c1-175dac7ddf02
endif

include ./tools/mk/Makefile.defs
include ./tools/mk/Makefile.node_deps.defs
ifeq ($(shell uname -s),SunOS)
include ./tools/mk/Makefile.node_prebuilt.defs
else
NODE := node
NPM := $(shell which npm)
NPM_EXEC=$(NPM)
endif

#
# Repo-specific targets
#
.PHONY: all test
all: $(REPO_DEPS)
.PHONY: all
all: $(NPM_EXEC)
$(NPM) install

$(ISTANBUL): | $(NPM_EXEC)
$(NPM) install

test:
$(TAP) test
$(FAUCET): | $(NPM_EXEC)
$(NPM) install

.PHONY: test
test: $(ISTANBUL) $(FAUCET)
$(NODE) $(ISTANBUL) cover --print none test/run.js | $(FAUCET)

CLEAN_FILES += ./node_modules ./build

include ./tools/mk/Makefile.deps
include ./tools/mk/Makefile.node_deps.targ
ifeq ($(shell uname -s),SunOS)
include ./tools/mk/Makefile.node_prebuilt.targ
endif
include ./tools/mk/Makefile.targ
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,31 @@ var log = bunyan.createLogger({

log.debug({foo: 'bar'}, 'hello %s', 'world');
```

That's pretty much it. You create a syslog stream, and point it at a syslog
server (UDP by default; you can force TCP by setting `type: tcp` in the
constructor); default is to use facility `user` and a syslog server on
`127.0.0.1:514`. Note you *must* pass `type: 'raw'` to bunyan in the top-level
stream object or this won't work.

If you want your logs to be in the normal bunyan format, `rsyslog` allows you to
setup a template to format it as just the JSON object:

```
template(name="bunyan" type="string"
string="%msg:R,ERE,1,FIELD:(\\{.*\\})--end%\n")
local0.* /var/log/application.log;bunyan
```

You can also write this using the older `$template` syntax:

```
$template bunyan,"%msg:R,ERE,1,FIELD:(\{.*\})--end%\n"
local0.* /var/log/application.log;bunyan
```

## Mappings

This module maps bunyan levels to syslog levels as follows:
Expand All @@ -53,6 +72,31 @@ This module maps bunyan levels to syslog levels as follows:
+--------+--------+
```

## Running the test suite

You can run the test suite using the provided `rsyslog` configuration:

```
$ rsyslogd -f ./test/rsyslog.conf -i ./test.pid -u $USER
$ make test
$ kill $(cat test.pid)
```

If you have an older `rsyslog` installed, you can adjust it to use the legacy
syntax:

```
$ModLoad imudp
$ModLoad imtcp
$UDPServerAddress 127.0.0.1
$UDPServerRun 10514
$InputTCPServerRun 10514
```

Note that when run this way, the TCP socket will listen on `0.0.0.0`.

# License

MIT.
2 changes: 1 addition & 1 deletion deps/javascriptlint
2 changes: 1 addition & 1 deletion deps/jsstyle
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var UDPStream = require('./udp');



///--- Globals
// --- Globals

var FACILITY = {
kern: 0,
Expand All @@ -35,7 +35,7 @@ var FACILITY = {



///--- Exports
// --- Exports

module.exports = {
createBunyanStream: function createBunyanStream(opts) {
Expand Down
35 changes: 21 additions & 14 deletions lib/sys.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2013 Mark Cavage, Inc. All rights reserved.

var dgram = require('dgram');
var os = require('os');
var Stream = require('stream').Stream;
var util = require('util');
Expand All @@ -11,25 +10,27 @@ var binding = require('../build/Release/syslog');



///--- Globals
// --- Globals

var sprintf = util.format;

var HOSTNAME = os.hostname();

// Harcoded from https://github.com/trentm/node-bunyan so this module
// can have minimal dependencies
/*
* Harcoded from https://github.com/trentm/node-bunyan so this module
* can have minimal dependencies.
*/
var bunyan = {
FATAL: 60,
ERROR: 50,
WARN: 40,
INFO: 30,
WARN: 40,
INFO: 30,
DEBUG: 20,
TRACE: 10,

safeCycles: function safeCycles() {
var seen = [];
function bunyanCycles(k, v) {
function bunyanCycles(_, v) {
if (!v || typeof (v) !== 'object') {
return (v);
}
Expand All @@ -45,7 +46,8 @@ var bunyan = {
};


// Syslog Levels
/* Syslog Levels */
/* eslint-disable */
var LOG_EMERG = 0;
var LOG_ALERT = 1;
var LOG_CRIT = 2;
Expand All @@ -54,9 +56,10 @@ var LOG_WARNING = 4;
var LOG_NOTICE = 5;
var LOG_INFO = 6;
var LOG_DEBUG = 7;
/* eslint-enable */


///--- Helpers
// --- Helpers

// Translates a Bunyan level into a syslog level
function level(l) {
Expand Down Expand Up @@ -94,7 +97,7 @@ function time(t) {



///--- API
// --- API

function SyslogStream(opts) {
assert.object(opts, 'options');
Expand Down Expand Up @@ -129,17 +132,19 @@ SyslogStream.prototype.destroy = function destroy() {


SyslogStream.prototype.end = function end() {
if (arguments.length > 0)
if (arguments.length > 0) {
this.write.apply(this, Array.prototype.slice.call(arguments));
}

this.writable = false;
this.close();
};


SyslogStream.prototype.write = function write(r) {
if (!this.writable)
if (!this.writable) {
throw new Error('SyslogStream has been ended already');
}

var h;
var l;
Expand Down Expand Up @@ -178,10 +183,12 @@ SyslogStream.prototype.write = function write(r) {

SyslogStream.prototype.toString = function toString() {
var str = '[object SyslogStream<facility=' + this.facility;
if (this.host)
if (this.host) {
str += ', host=' + this.host;
if (this.port)
}
if (this.port) {
str += ', port=' + this.port;
}
if (!/^Sys/.test(this.constructor.name)) {
str += ', proto=' +
(/UDP/.test(this.constructor.name) ? 'udp' : 'tcp');
Expand Down
9 changes: 5 additions & 4 deletions lib/tcp.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var SyslogStream = require('./sys');



///--- Globals
// --- Globals

var PROXY_EVENTS = [
'connect',
Expand All @@ -22,7 +22,7 @@ var PROXY_EVENTS = [



///--- Helpers
// --- Helpers

function createSocket(opts) {
assert.object(opts, 'options');
Expand All @@ -44,7 +44,7 @@ function createSocket(opts) {



///--- API
// --- API

function TCPStream(opts) {
assert.object(opts, 'options');
Expand Down Expand Up @@ -72,8 +72,9 @@ function TCPStream(opts) {
});
self.socket.removeAllListeners('close');
self.socket.removeAllListeners('error');
if (self.socket.destroy)
if (self.socket.destroy) {
self.socket.destroy();
}
}

self.socket = createSocket({
Expand Down
5 changes: 3 additions & 2 deletions lib/udp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var SyslogStream = require('./sys');



///--- API
// --- API

function UDPStream(opts) {
assert.object(opts, 'options');
Expand Down Expand Up @@ -50,8 +50,9 @@ UDPStream.prototype._send = function _send(msg) {

this._pending++;
s.send(buf, 0, buf.length, this.port, this.host, function (err) {
if (err)
if (err) {
self.emit('error', err);
}

self._pending--;
});
Expand Down
Loading

0 comments on commit c3daebf

Please sign in to comment.