Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 68d1f1b5ba9ddb03255bbd24f7457242a90b119b @hmalphettes committed May 23, 2013
Showing with 1,007 additions and 0 deletions.
  1. +13 −0 .gitignore
  2. +36 −0 .jshintrc
  3. +16 −0 .tm_properties
  4. +48 −0 Makefile
  5. +157 −0 README.md
  6. +33 −0 lib/elasticsearch-client.js
  7. +196 −0 lib/log4js-elasticsearch-layouts.js
  8. +131 −0 lib/log4js-elasticsearch.js
  9. +31 −0 package.json
  10. +114 −0 test/integration/test-real-eslogger.js
  11. +232 −0 test/test-eslogger.js
@@ -0,0 +1,13 @@
+node_modules
+npm-debug.log
+.DS_Store
+meta.json
+.idea
+coverage.html
+lib-cov
+.coverage_data
+reports
+html-report
+build
+cobertura-coverage.xml
+metadata
@@ -0,0 +1,36 @@
+{
+ "proto": true,
+ "browser": true,
+ "curly": true,
+ "devel": true,
+ "eqeqeq": true,
+ "eqnull": true,
+ "es5": false,
+ "evil": false,
+ "immed": false,
+ "jquery": true,
+ "latedef": false,
+ "laxcomma": true,
+ "newcap": true,
+ "node": true,
+ "noempty": true,
+ "nonew": true,
+ "predef":
+ [
+ "after",
+ "afterEach",
+ "before",
+ "beforeEach",
+ "describe",
+ "it",
+ "unescape",
+ "par",
+ "each",
+ "setImmediate"
+ ],
+ "smarttabs": true,
+ "trailing": false,
+ "undef": true,
+ "strict": false,
+ "expr": true
+}
@@ -0,0 +1,16 @@
+fontName = "Monaco"
+fontSize = 12
+
+myExtraExcludes = "log,vendor,tmp,node_modules"
+excludeInFileChooser = "{$excludeInFileChooser,$myExtraExcludes}"
+excludeInFolderSearch = "{$excludeInFolderSearch,$myExtraExcludes}"
+excludeInBrowser = "{$excludeInBrowser,log,vendor,tmp,node_modules}"
+
+showInvisibles = true
+softTabs = true
+tabSize = 2
+wrapColumn = 120
+showWrapColumn = true
+
+projectDirectory = "$CWD"
+windowTitle = "$TM_DISPLAYNAME — ${CWD/^.*\///} ($TM_SCM_BRANCH)"
@@ -0,0 +1,48 @@
+BIN = ./node_modules/.bin
+MOCHA_OPTS = --timeout 2000
+REPORTER = spec
+TEST_FILES = test/*.js
+TEST_INTEGRATION_FILES = test/integration/*.js
+S3_STOIC=s3cmd -c ~/.s3cmd/.stoic
+S3_NPM_REPO=s3://npm-repo
+
+lint:
+ jshint lib/* test/* --config .jshintrc
+
+test: lint
+ ./node_modules/.bin/mocha \
+ $(MOCHA_OPTS) \
+ --reporter $(REPORTER) \
+ $(TEST)
+
+test-integration: lint
+ ./node_modules/.bin/mocha \
+ $(MOCHA_OPTS) \
+ --reporter $(REPORTER) \
+ $(TEST_INTEGRATION_FILES)
+
+test-ci:
+ $(MAKE) -k test MOCHA_OPTS="$(MOCHA_OPTS) --watch --growl" REPORTER="min"
+
+lib-cov:
+ [ -d "lib-cov" ] && rm -rf lib-cov || true
+ $(BIN)/istanbul instrument --output lib-cov --no-compact --variable global.__coverage__ lib
+
+test-cov: lib-cov
+ @LOG4JS_COV=1 $(MAKE) test "REPORTER=mocha-istanbul" ISTANBUL_REPORTERS=text-summary,html
+
+clean:
+ [ -d "lib-cov" ] && rm -rf lib-cov || true
+ [ -d "reports" ] && rm -rf reports || true
+ [ -d "build" ] && rm -rf build || true
+
+install-local:
+ @npm install
+ @npm link ../mapperjs || true
+
+deploy:
+ @npm pack
+ $(S3_STOIC) put *.tgz $(S3_NPM_REPO)
+ rm *.tgz
+
+.PHONY: test
157 README.md
@@ -0,0 +1,157 @@
+log4js-elasticsearch
+====================
+
+log4js-elasticsearch is a log4js log appender to push log messages into [elasticsearch](http://elasticsearch.org).
+[Kibana](http://kibana.org) is the awesome tool to view the logs.
+
+The logs produced are compatible with [logstash's elasticsearch_http output](logstash.net/docs/1.1.12/outputs/elasticsearch_http).
+
+Installation
+------------
+
+You can install install log4js-elasticsearch via npm:
+
+ npm install log4js-elasticsearch
+
+Usage: basic
+------------
+
+ var log4js = require('log4js');
+ var esAppenderConfig = {
+ url: 'http://user:password@myelasticsearch.com:9200'
+ };
+ var log4jsESAppender = require('log4js-elasticsearch').configure(esAppenderConfig);
+ log4js.addAppender(log4js, 'tests');
+
+The default url of the ES server is http://localhost:9200
+
+Usage: log4js configuration
+---------------------------
+
+ var log4js = require('log4js');
+ log4js.configure({
+ "appenders": [
+ {
+ "category": "tests",
+ "type": "logLevelFilter",
+ "level": "WARN",
+ "appender": {
+ "type": "log4js-elasticsearch",
+ "url": "http://127.0.0.1:9200"
+ }
+ },
+ {
+ "category": "tests",
+ "type": "console",
+ }
+ ],
+ "levels": {
+ "tests": "DEBUG"
+ }
+ });
+
+Usage: advanced
+---------------
+
+ var log4js = require('log4js');
+ log4js.configure({
+ "appenders": [
+ "appender": {
+ "type": "log4js-elasticsearch",
+ "indexName": function(loggingEvent) {
+ return loggingEvent.categoryName;
+ },
+ "typeName": function(loggingEvent) {
+ return loggingEvent.level.levelStr;
+ },
+ "url": "http://127.0.0.1:9200",
+ "layout": {
+ "type": "logstash",
+ "tags": [ "mytag" ],
+ "sourceHost": function(loggingEvent) {
+ return "it-depends";
+ }
+ }
+ }
+ ],
+ "levels": {
+ "tests": "DEBUG"
+ }
+ });
+
+
+Appender configuration parameters
+=================================
+- `url`: the URL of the elasticsearch server.
+Basic authentication is supported.
+Default: http://localhost:9200
+
+- `indexName`: the name of the elasticsearch index in which the logs are stored.
+Either a static string either a function that is passed the logging event.
+Defaults: undefined'; The indexNamePrefix is used by default.
+
+- `indexNamePrefix`: the prefix of the index name in which the logs are stored.
+The name of the actual index is suffixed with the date: `%{+YYYY.MM.dd}` and changes every day, UTC time.
+Defaults: 'logstash-'.
+
+- `typeName`: the name of the elasticsearch object in which the logs are posted.
+Either a string or a function that is passed the logging event.
+Default: 'nodejs'.
+
+- `wrapper`: function that wraps the serialization of a logging event into the data stored in Elasticsearch.
+A function that is passed the output of the layout and returns what gets posted into elasticsearch.
+When the value is the string 'logstash' it uses the built-in logstash wrapper.
+When the value is 'simple' or 'passthrough' it passes along the output of the layout.
+Default: the built-in logstashWrapper.
+
+- `layout`: object descriptor for the layout.
+By default the layout is logstash.
+
+Additional Built-in layouts
+============================
+
+The following layouts are added to the log4js builtin layouts:
+- logstash
+- simpleJson
+
+The following parameters are the children of the `layout` parameter in the appender's configuration for those new built-in layouts.
+
+Default: Logstash layout
+------------------------
+The logstash layout posts logs in the same structure than [logstash's elasticsearch_http output](logstash.net/docs/1.1.12/outputs/elasticsearch_http).
+
+- `tags`: output as the value of the `@tags` property.
+A static array or a function that is passed the logging event.
+Default: empty array.
+
+- `sourceHost`: output as the value of the `@source_host` property.
+A static string or a function that is passed the logging event
+Default: OS's hostname.
+
+- `source`: output as the value of the `@source` property.
+A string.
+Default: 'log4js'.
+
+- `sourcePath`: output as the value of the `@source_path` property
+A string.
+Default: working directory of the current process.
+
+- `logId`: outputs the value of the `_id` field.
+A function or undefined to let elasticsearch generates it.
+Default: undefined.
+
+- `template`: the elasticsearch template to define.
+Only used if no template with the same name is defined.
+Default: from [untergeek's using-templates-to-improve-elasticsearch-caching-with-logstash](http://untergeek.com/2012/09/20/using-templates-to-improve-elasticsearch-caching-with-logstash/).
+
+simpleJson Layout
+-----------------
+A simple message pass through of the loggingEvent.
+
+License
+=======
+MIT
+
+Copyright
+=========
+(c) 2013 Sutoiku, Inc.
@@ -0,0 +1,33 @@
+var parseUrl = require('url').parse;
+var ElasticSearchClient = require('elasticsearchclient');
+
+/**
+ * Parses a URL with optional login / password
+ * returns the expected json options to configure the connection to ES.
+ */
+ElasticSearchClient.makeOptions = function(url) {
+ var urlP = parseUrl(url);
+ var options = {
+ host: urlP.hostname
+ };
+ var secure = urlP.protocol === 'https:';
+ if (urlP.port !== null && urlP.port !== undefined) {
+ options.port = urlP.port;
+ } else if (secure) {
+ options.port = '443';
+ } else {
+ options.port = '80';
+ }
+ options.secure = secure;
+ if (urlP.auth) {
+ var toks = urlP.auth.split(':');
+ if (toks.length === 2) {
+ options.auth = { username: toks[0], password: toks[1] };
+ } else {
+ options.auth = { username: toks[0], password: '' };
+ }
+ }
+ return options;
+};
+
+module.exports = ElasticSearchClient;
Oops, something went wrong.

0 comments on commit 68d1f1b

Please sign in to comment.