Last active
April 19, 2016 17:11
-
-
Save mcasimir/4db15d462ae9ade847f3d1887c7da292 to your computer and use it in GitHub Desktop.
winston console -> docker gelf log -> logstash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
let winston = require('winston'); | |
// | |
// Test with json format | |
// | |
let logger = new winston.Logger({ | |
transports: [ | |
new winston.transports.Console({ | |
handleExceptions: true, | |
json: true, | |
stringify: true | |
}) | |
], | |
exitOnError: false | |
}); | |
logger.log('error', `Error Message json`, {anything: 'This is metadata'}); | |
logger.log('info', `Info Message json`, {anything: 'This is metadata'}); | |
// | |
// Test with default kv format | |
// | |
logger = new winston.Logger({ | |
transports: [ | |
new winston.transports.Console({ | |
handleExceptions: true | |
}) | |
], | |
exitOnError: false | |
}); | |
logger.log('error', `Error Message kv`, {a: 'This is metadata', b: 'x'}); | |
logger.log('info', `Info Message kv`, {anything: 'This is metadata'}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input { | |
gelf { | |
port => 5229 | |
} | |
} | |
filter { | |
mutate { | |
replace => { "full_message" => "%{message}" } | |
} | |
if [message] =~ /^{.*}$/ | |
{ | |
json { | |
source => "message" | |
target => "fields" | |
} | |
mutate { | |
add_field => ["level_name", "%{[fields][level]}"] | |
} | |
mutate { | |
replace => { "message" => "%{[fields][message]}" } | |
} | |
mutate { | |
remove_field => [ "[fields][level]", "[fields][message]" ] | |
} | |
} else { | |
grok { | |
match => { "message" => "(?<level_name>^(emerg|alert|crit|error|warn|warning|notice|info|verbose|debug|silly)): " } | |
} | |
mutate { | |
gsub => [ "message", "=([^,]*),", "=[\1],"] | |
} | |
mutate { | |
gsub => [ "message", "=([^,]*)$", "=[\1]"] | |
} | |
kv { | |
source => "message" | |
target => "fields" | |
recursive => "true" | |
field_split => ", " | |
} | |
mutate { | |
gsub => [ "message", " [A-z][A-z0-9]*=([^,]*)(,|$)", ""] | |
} | |
mutate { | |
gsub => [ "message", "^(emerg|alert|crit|error|warn|warning|notice|info|verbose|debug|silly): ", ""] | |
} | |
} | |
} | |
output { | |
elasticsearch { | |
hosts => "elasticsearch:9200" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
docker run \ | |
-v ${PWD}/index.js:/index.js \ | |
-v ${PWD}/package.json:/package.json \ | |
-v ${PWD}/node_modules:/node_modules \ | |
--label greet=hi \ | |
--log-driver=gelf \ | |
--log-opt gelf-address=udp://192.168.99.100:5229 \ | |
--log-opt tag="docker-stage" \ | |
--log-opt labels=greet \ | |
node:4-slim \ | |
node index.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment