Commit b3fcfedb authored by Peter Müller's avatar Peter Müller

Initial commit

parents
Pipeline #173 passed with stages
in 27 seconds
node_modules
.js
*.tgz
image: crycode/nodejs-dev-env
stages:
- build
- deploy
cache:
paths:
- node_modules/
coffee-build:
stage: build
artifacts:
expire_in: 1 week
name: "coffee-build-${CI_COMMIT_SHA:0:8}"
paths:
- .js/
script:
- coffee -c -o .js *.coffee
publish-to-npm:
stage: deploy
script:
- npm config set unsafe-perm true
- npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
- npm publish
environment:
name: production
url: https://www.npmjs.com/package/pimatic-log-to-syslog
when: manual
only:
- tags
## v1.0.0 2017-12-25
- First release
This diff is collapsed.
# pimatic-log-to-syslog
[![build status](https://git.cryhost.de/crycode/pimatic-log-to-syslog/badges/master/build.svg)](https://git.cryhost.de/crycode/pimatic-log-to-syslog/commits/master)
[![npm version](https://badge.fury.io/js/pimatic-log-to-syslog.svg)](https://badge.fury.io/js/pimatic-netcheck)
`pimatic-log-to-syslog` is a [pimatic](https://github.com/pimatic/pimatic) plugin that sends the pimatic log to the syslog.
If this plugin is enabled, any log message of pimatic is send to syslog.
By default the log level (debug, info, warning, errro) of each message will be detected and the level of the syslog message will be set accordingly.
Please notice, that the first few log messages on pimatic startup can't be send to syslog. This is because the plugin must be loaded by pimatic to enable the syslog ability.
## License
Licensed under GPL Version 2
Copyright (c) 2017 Peter Müller <peter@crycode.de> (https://crycode.de/)
module.exports = {
title: "Log to syslog config options"
type: "object"
properties:
name:
description: "The process name in syslog."
type: "string"
default: "pimatic"
detectLogLevel:
description: "Should we detect the level (error, warning, info, debug) of each log entry and pass it to syslog?"
type: "boolean"
default: true
testLogLevel:
description: "Enable some test messages for info, debug, warning and error logging on startup."
type: "boolean"
default: false
}
# pimatic-log-to-syslog
#
# Pimatic plugin to copy the pimatic log to syslog
#
# Licensed under GPL Version 2
#
# Copyright (c) 2017 Peter Müller <peter@crycode.de> (https://crycode.de/)
#
module.exports = (env) ->
# moden-syslog is used to send the log entries to syslog
syslog = require 'modern-syslog'
# ###PimaticLogToSyslog class
class PimaticLogToSyslog extends env.plugins.Plugin
init: (app, @framework, @config) =>
syslogName = @config.name or "pimatic"
detectLogLevel = if @config.detectLogLevel? then @config.detectLogLevel else true
# init the syslog
syslog.init syslogName, syslog.LOG_PID | syslog.LOG_ODELAY, syslog.LOG_DAEMON
# original output functions
process.stdout.writeLogToSyslogOrig = process.stdout.write
process.stderr.writeLogToSyslogOrig = process.stderr.write
# new output function for stdout
process.stdout.write = (string) =>
# original output
process.stdout.writeLogToSyslogOrig string
# detect the log level
if detectLogLevel
if string.match(/\] debug: /) or string.match(/\]\x1B[[(?);]39m\x1B[[(?);]90m \x1B[[(?);]39m\x1B[[(?);]34m/)
logLevel = syslog.LOG_DEBUG
else if string.match(/\] warn: /) or string.match(/\]\x1B[[(?);]39m\x1B[[(?);]90m \x1B[[(?);]39m\x1B[[(?);]33m/)
logLevel = syslog.LOG_WARNING
else if string.match(/\] error: /) or string.match(/\]\x1B[[(?);]39m\x1B[[(?);]90m \x1B[[(?);]39m\x1B[[(?);]31m/)
logLevel = syslog.LOG_ERR
else
logLevel = syslog.LOG_INFO
else
logLevel = syslog.LOG_INFO
# strip out ansi characters
string = string.replace /\x1B[[(?);]{0,2}(;?\d)*./g, ""
# remove the tailing timestamp
string = string.replace /^\d\d:\d\d:\d\d\.\d\d\d /, ""
# log to syslog using the detected log level
syslog.log logLevel, string
# new output function for stderr
process.stderr.write = (string) =>
# original output
process.stderr.writeLogToSyslogOrig string
# strip out ansi characters
string = string.replace /\x1B[[(?);]{0,2}(;?\d)*./g, ""
# remove the tailing timestamp
string = string.replace /^\d\d:\d\d:\d\d\.\d\d\d /, ""
# log to syslog always as error
syslog.log syslog.LOG_ERR, string
# log info that the log is now send to syslog
env.logger.info "pimatic is now logging to syslog"
# testing
if @config.testLogLevel
env.logger.info '*** test info ***'
env.logger.debug '*** test debug ***'
env.logger.warn '*** test warn ***'
env.logger.error '*** test error ***'
# Create a instance of the plugin
pimaticLogToSyslog = new PimaticLogToSyslog
# ###Finally
# return it to the framework.
return pimaticLogToSyslog
{
"name": "pimatic-log-to-syslog",
"description": "Pimatic plugin to send the pimatic log to syslog",
"author": "Peter Müller <peter@crycode.de> (https://crycode.de)",
"keywords": [
"log",
"logging",
"syslog",
"pimatic"
],
"main": "log-to-syslog",
"files": [
"CHANGELOG.md",
"LICENSE.md",
"log-to-syslog-config-schema.coffee",
"log-to-syslog.coffee",
"README.md"
],
"version": "1.0.0",
"license": "GPL-2.0",
"configSchema": "log-to-syslog-config-schema.coffee",
"homepage": "https://git.cryhost.de/crycode/pimatic-log-to-syslog",
"repository": {
"type": "git",
"url": "https://git.cryhost.de/crycode/pimatic-log-to-syslog.git"
},
"bugs": {
"url": "https://git.cryhost.de/crycode/pimatic-log-to-syslog/issues"
},
"dependencies": {
"modern-syslog": "^1.1.4"
},
"peerDependencies": {
"pimatic": "0.9.*"
},
"engines": {
"node": ">4.x.x",
"npm": ">1.1.x"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment