UNPKG

2.9 kBJavaScriptView Raw
1'use strict'
2
3//const elasticsearch = require('elasticsearch');
4const AWS = require('aws-sdk');
5const winstonAwsCloudWatch = require('winston-aws-cloudwatch');
6const winston = require('winston');
7//const awses = require('http-aws-es');
8//const WinstonElasticsearch = require('winston-elasticsearch');
9const fs = require('fs');
10const path = require('path');
11
12const logDir = 'log';
13// Create the log directory if it does not exist
14// if (!fs.existsSync(logDir)) {
15// fs.mkdirSync(logDir);
16// }
17// const filename = path.join(logDir, 'results.log');
18
19const region = 'us-east-1';
20//const hosts = ['https://search-aws-es-v-n67kab4wame7fzgneuw7qzehia.us-east-1.es.amazonaws.com'];
21
22module.exports.offTransport = () => {
23 return {
24 transports: []
25 };
26}
27
28module.exports.consoleTransport = () => {
29 return {
30 transports: [
31 new (winston.transports.Console)({ level: 'info' }),
32 ]
33 };
34}
35
36// Replaces the previous transports with those in the
37// new configuration wholesale.
38//
39// const DailyRotateFile = require('winston-daily-rotate-file');
40// logger.configure({
41// level: 'verbose',
42// transports: [
43// new DailyRotateFile(opts)
44// ]
45// });
46
47module.exports.fileTransport = () => {
48 return {
49 transports: [
50 // - Write to all logs with level `info` and below to `combined.log`
51 // - Write all logs error (and below) to `error.log`.
52 new winston.transports.File({ filename: 'error.log', level: 'error' }),
53 new winston.transports.File({ filename: 'invoicing.log' }),
54 ]
55 };
56}
57
58module.exports.awsTransport = (module) => {
59 const awsConfig = {
60 region: region
61 }
62
63 // const client = elasticsearch.Client({
64 // hosts: hosts,
65 // connectionClass: awses,
66 // log: 'trace'
67 // });
68
69 //Configuring AWS Credentials once
70 AWS.config.update({
71 region: region
72 });
73
74 return {
75 transports: [
76 new (winstonAwsCloudWatch)({
77 level: 'info',
78 timestamp: () => {
79 return new Date().toString()
80 },
81 json: true,
82 logGroupName: 'apfTest', // REQUIRED
83 // logStreamName: module, // REQUIRED
84 logStreamName: 'invoicing', // REQUIRED
85 createLogGroup: true,
86 createLogStream: true,
87 awsRegion: 'us-east-1',
88 formatLog: function (item) {
89 return item.level + ': ' + item.message + ' ' + JSON.stringify(item.meta)
90 }
91 }),
92 // new (WinstonElasticsearch)({
93 // level: 'info',
94 // client: client,
95 // formatLog: function (item) {
96 // return item.level + ': ' + item.message + ' ' + JSON.stringify(item.meta)
97 // }
98 // })
99 ]
100 };
101}