-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
55 lines (48 loc) · 1.49 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var winston = require('winston');
require('winston-loggly');
var Promise = require('bluebird');
// Replace these with your Loggly credentials
var LogglyEnv = {
tags: process.env.LOGGLY_TAGS,
token: process.env.LOGGLY_TOKEN,
subdomain: process.env.LOGGLY_SUBDOMAIN
}
var loglevel = ['info', 'warning', 'error', 'fatal', 'debug', 'trace'];
/***
* function Log(LogglyData)
*
* LogglyData: string
* The name of the function you are logging from. This will be added as a tag.
*
* LogglyData: Object
* {
* token: string,
* subdomain: string,
* tags: array of string || string
* }
*/
module.exports.Log = function(LogglyData) {
var tags = [],
envTags = [],
dataTags = [];
if ('string' == typeof LogglyData) { LogglyData = {tags: [LogglyData]}; }
if (LogglyEnv.tags) { envTags = LogglyEnv.tags; }
if ('string' == typeof envTags) { envTags = [envTags] };
if (LogglyData.tags) { dataTags = LogglyData.tags; }
if ('string' == typeof dataTags) { envTags = [dataTags] };
tags = envTags.concat(dataTags);
var Loggly = {
token: LogglyData.token || LogglyEnv.token,
subdomain: LogglyData.subdomain || LogglyEnv.subdomain,
tags: tags
}
console.log(Loggly);
winston.add(winston.transports.Loggly, {
token: Loggly.token,
subdomain: Loggly.subdomain,
tags: Loggly.tags,
json:true
});
var PromisifiedLog = Promise.promisify(winston.log);
return PromisifiedLog;
}