Skip to content

Instantly share code, notes, and snippets.

@pooza
Last active June 3, 2017 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pooza/695340ba8d2f3e39f1a35bcd0c67e497 to your computer and use it in GitHub Desktop.
Save pooza/695340ba8d2f3e39f1a35bcd0c67e497 to your computer and use it in GitHub Desktop.
npmlogと多分互換。MastodonのストリーミングAPIが吐き出すログを、syslogに流すやつ。
// 使い方
//
// このソースを streaming/node_modules/bslogger.js という名前で保存。
// shell-escapeが必要なので、streamingディレクトリに居る時に npm install shell-escape とか実行。
//
// そうしたら、index.jsの以下の行を、
// import log from 'npmlog';
//
// 以下の2行に置き換え。log.nameはお好みに合わせて。
// import log from 'bslogger';
// log.name = 'mastodon_streaming';
this.name = 'bslogger';
this.error = function (arg1, arg2) {
this.log(arg1, arg2);
}
this.info = function (arg1, arg2) {
this.log(arg1, arg2);
}
this.verbose = function (arg1, arg2) {
this.log(arg1, arg2);
}
this.silly = function (arg1, arg2) {
this.log(arg1, arg2);
}
this.log = function (arg1, arg2) {
var exec = require('child_process').exec;
var shellescape = require('shell-escape');
var command = [
'logger',
'-t', shellescape([this.name]),
shellescape([arg1, arg2]),
].join(' ');
//console.log(command);
exec(command);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment