Skip to content

Commit

Permalink
initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlevesque committed Jun 24, 2018
0 parents commit 1225e7b
Show file tree
Hide file tree
Showing 6 changed files with 879 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .gitignore
@@ -0,0 +1,60 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

.openode

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: node_js
node_js:
- '8'
- '7'
64 changes: 64 additions & 0 deletions index.js
@@ -0,0 +1,64 @@

const request = require('request')

function _post(path, content, opts = {}) {
return new Promise((resolve, reject) => {
const options = {
uri: (process.env.URL || 'https://traceify.openode.io') + path,
method: 'POST',
json: content,
headers: {
"content-type": "application/json",
"x-auth-token": opts.token
}
}

request(options, function (error, response, body) {
if ( ! error && response.statusCode == 200) {
resolve(body)
} else {
reject(error || body)
}
})
})
}

function _log(level, content, opts = {}) {
return _post(`/api/v1/instances/${opts.site_name}/${level}/log`, content, opts)
}

function _search(level, content, opts = {}) {
return _post(`/api/v1/instances/${opts.site_name}/${level}/search`, content, opts)
}

module.exports = function(opts = {}) {
return {
log: function(level, content) {
return _log(level, content, opts)
},

info: function(content) {
return _log('info', content, opts)
},

warn: function(content) {
return _log('warn', content, opts)
},

error: function(content) {
return _log('error', content, opts)
},

debug: function(content) {
return _log('debug', content, opts)
},

trace: function(content) {
return _log('trace', content, opts)
},

search: function(level, content) {
return _search(level, content, opts)
},
}
}

0 comments on commit 1225e7b

Please sign in to comment.