Skip to content

Commit

Permalink
chore(package): initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: kevin.bonduelle <[email protected]>
  • Loading branch information
kevin.bonduelle committed Apr 25, 2017
0 parents commit 893e800
Show file tree
Hide file tree
Showing 13 changed files with 1,408 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
76 changes: 76 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"disallowEmptyBlocks": true,
"disallowKeywords": ["with"],
"disallowKeywordsOnNewLine": ["else"],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineBreaks": false,
"disallowMultipleLineStrings": true,
"disallowMultipleVarDecl": true,
"disallowNewlineBeforeBlockStatements": true,
"disallowSpaceAfterObjectKeys": false,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforeComma": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceBeforeSemicolon": true,
"disallowSpacesInCallExpression": true,
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpacesInsideParentheses": true,
"disallowTrailingWhitespace": true,
"disallowYodaConditions": true,
"requireCapitalizedConstructors": true,
"requireCommaBeforeLineBreak": true,
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireDotNotation": true,
"requireOperatorBeforeLineBreak": true,
"requireParenthesesAroundIIFE": true,
"requireSemicolons": true,
"requireSpaceAfterBinaryOperators": true,
"requireSpaceAfterComma": true,
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBinaryOperators": [
"=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=",
"&=", "|=", "^=", "+=",

"+", "-", "*", "/", "%", "<<", ">>", ">>>", "&",
"|", "^", "&&", "||", "===", "==", ">=",
"<=", "<", ">", "!=", "!=="
],
"excludeFiles": [
"client/app/config/custom.js",
],
"requireSpaceBeforeBlockStatements": true,
"requireSpaceBeforeObjectValues": true,
"requireSpaceBetweenArguments": true,
"requireSpacesInConditionalExpression": true,
"requireSpacesInForStatement": true,
"requireSpacesInFunctionDeclaration": {
"beforeOpeningCurlyBrace": true,
"beforeOpeningRoundBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true,
"beforeOpeningRoundBrace": true
},
"requireSpacesInsideObjectBrackets": "all",
"validateIndentation": 4,
"validateParameterSeparator": ", ",
"validateQuoteMarks": "\""
}
36 changes: 36 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"bitwise" : false,
"node" : true,
"curly" : true,
"eqeqeq" : true,
"forin" : true,
"immed" : true,
"indent" : 4,
"latedef" : true,
"newcap" : true,
"noarg" : true,
"noempty" : true,
"nonew" : false,
"plusplus" : false,
"undef" : true,
"unused" : true,
"strict" : true,
"asi" : false,
"debug" : true,
"eqnull" : true,
"funcscope" : false,
"devel" : true,
"esnext": true,
"globals": {
"console" : true,
"_" : true,
"describe" : true,
"beforeEach" : true,
"module" : true,
"it" : true,
"expect" : true,
"by" : true,
"afterEach" : true,
"require" : true
}
}
17 changes: 17 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# This is the official list of authors for copyright purposes.
# This file is distinct from the CONTRIBUTORS files.
# See the latter for an explanation.
#
# Names should be added to this file as one of
# Organization's name
# Individual's name <submission email address>
# Individual's name <submission email address> <email2> <emailN>
# See CONTRIBUTORS for the meaning of multiple email addresses.

# Please keep the list sorted.

Pierre De Paepe <[email protected]>
Cyrille Meichel <[email protected]>
Cyril Biencourt <[email protected]>
Kévin Bonduelle <[email protected]>
72 changes: 72 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Contributing to ovh-winston-ldp

This project accepts contributions. In order to contribute, you should
pay attention to a few things:

1. your code must follow the coding style rules
2. your code must be unit-tested
3. your code must be documented
4. your work must be signed (see below)
5. you may contribute through GitHub Pull Requests

# Coding and documentation Style

- Lint your code with stylelint: yarn lint.
- Lint your code with stylelint: yarn test.

# Submitting Modifications

The contributions should be submitted through Github Pull Requests
and follow the DCO which is defined below.

# Licensing for new files

ovh-winston-ldp is licensed under a (modified) BSD license license. Anything
contributed to ovh-winston-ldp must be released under this license.

When introducing a new file into the project, please make sure it has a
copyright header making clear under which license it's being released.

# Developer Certificate of Origin (DCO)

To improve tracking of contributions to this project we will use a
process modeled on the modified DCO 1.1 and use a "sign-off" procedure
on patches that are being emailed around or contributed in any other
way.

The sign-off is a simple line at the end of the explanation for the
patch, which certifies that you wrote it or otherwise have the right
to pass it on as an open-source patch. The rules are pretty simple:
if you can certify the below:

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I have
the right to submit it under the open source license indicated in
the file; or

(b) The contribution is based upon previous work that, to the best of
my knowledge, is covered under an appropriate open source License
and I have the right under that license to submit that work with
modifications, whether created in whole or in part by me, under
the same open source license (unless I am permitted to submit
under a different license), as indicated in the file; or

(c) The contribution was provided directly to me by some other person
who certified (a), (b) or (c) and I have not modified it.

(d) The contribution is made free of any other party's intellectual
property claims or rights.

(e) I understand and agree that this project and the contribution are
public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.


then you just add a line saying

Signed-off-by: Random J Developer <[email protected]>

using your real name (sorry, no pseudonyms or anonymous contributions.)
25 changes: 25 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2013-2017, OVH SAS.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of OVH SAS nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY OVH SAS AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL OVH SAS AND CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# ovh-winston-ldp

A [graylog2][0] TCP/TLS transport for [winston][1] library

```javascript
const winston = require('winston');
winston.add(require('ovh-winston-ldp'), {
level: 'debug',
graylogOvhTokenValue: "GRAY_LOG_TOKEN"
});

logger.info("Hello world!");
logger.log('warn', 'Test Log Message', {"anything": 'This is metadata' });
```


## Installation

Winston-graylog works with NodeJS 6.0.0+.

The easiest way to install it is to use [yarn](https://yarnpkg.com/en/)

```bash
$yarn add git://github.com/ovh/ovh-winston-ldp.git
```

## Usage
```javascript
const winston = require('winston');
winston.add(require('ovh-winston-ldp'), options);

```

or

```javascript
const OvhWinstonLDP = require('ovh-winston-ldp');
const logger = new(winston.Logger)({
exitOnError: false,
transports: [
new(OvhWinstonLDP)(options)
]
});
```

## Options

* __name__: Transport name
* __level__: Level of messages this transport should log. (default: info)
* __silent__: Boolean flag indicating whether to suppress output. (default: false)
* __graylogHost__: your server address (default: localhost)
* __graylogPort__: your server port (default: 12201)
* __graylogFlag__: Required on Thot Alpha
* __graylogOvhTokenKey__: Required on Thot Beta
* __graylogOvhTokenValue__: Required on Thot Beta
* __hostname__: the name of this host (default: os.hostname())
* __facility__: the facility for these log messages (default: "Node.js")


## Log Levels
Supported log levels, are the following

Winston Level | Graylog2 level
---------------|---------------
emerg | emergency
alert | alert
crit | critical
error | error
warning | warning
notice | notice
info | info
debug | debug

**All other possibile winston's level, or custom levels, will default to `info`**

[0]: http://www.graylog2.org
[1]: https://github.com/flatiron/winston
46 changes: 46 additions & 0 deletions lib/message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"use strict";

const MESSAGE_LEVEL = {
"silly": 7,
"debug": 7,
"verbose": 6,
"data": 6,
"prompt": 6,
"input": 6,
"info": 6,
"help": 5,
"notice": 5,
"warn": 5,
"warning": 5,
"error": 3,
"crit": 2,
"alert": 1,
"emerg": 0
};

class Message {

constructor(winstonLevel, msg, meta) {
this.level = Message.getMessageLevel(winstonLevel);
this.meta = meta;
this.msg = msg;
}

/**
* Convert string message type in message level
* @param {String} winstonLevel Message type
* @return {Number}
*/
getMessageLevel(winstonLevel) {
return Message.getMessageLevel(winstonLevel);
}

static getMessageLevel(winstonLevel) {
if (MESSAGE_LEVEL.hasOwnProperty(winstonLevel)) {
return MESSAGE_LEVEL[winstonLevel];
}
return 6;
}
}

module.exports = Message;
Loading

0 comments on commit 893e800

Please sign in to comment.