add logging and ignore logs
This commit is contained in:
parent
b0ef1fe89a
commit
b2f6c7c64a
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
|
logger.lock
|
||||||
|
logs
|
@ -7,7 +7,7 @@ module.exports = {
|
|||||||
mrt = mrt[0] + "." + mrt[1]
|
mrt = mrt[0] + "." + mrt[1]
|
||||||
return mrt
|
return mrt
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Error')
|
logger.info('Error')
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -21,7 +21,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
return on
|
return on
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Error')
|
logger.info('Error')
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
14
lib/logger.js
Normal file
14
lib/logger.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Load the perfect-logger module
|
||||||
|
let logger = require('perfect-logger');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
logger: () => {
|
||||||
|
// Configure Settings
|
||||||
|
logger.initialize('FrontEndDriver', {
|
||||||
|
logLevelFile: 0, // Log level for file
|
||||||
|
logLevelConsole: 0, // Log level for STDOUT/STDERR
|
||||||
|
logDirectory: 'logs/', // Log directory
|
||||||
|
customBannerHeaders: 'This is a custom banner' // Custom Log Banner
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
const got = require('got')
|
const got = require('got')
|
||||||
const token = require('basic-auth-token');
|
const token = require('basic-auth-token');
|
||||||
|
let logger = require('perfect-logger')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
postRequest: async (body, url) => {
|
postRequest: async (body, url) => {
|
||||||
@ -15,9 +16,14 @@ module.exports = {
|
|||||||
try {
|
try {
|
||||||
const response = await got('https://public.wcs.schneider-electric.ws/rpc/public_genie/' + url, options);
|
const response = await got('https://public.wcs.schneider-electric.ws/rpc/public_genie/' + url, options);
|
||||||
const res = JSON.parse(response.body)
|
const res = JSON.parse(response.body)
|
||||||
|
logger.info(url + " - ZONES - " + res.updateData.zones.length)
|
||||||
|
if (res.updateData.zones.length <2){
|
||||||
|
logger.info(JSON.stringify(res))
|
||||||
|
}
|
||||||
return res
|
return res
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('post error');
|
logger.info(error)
|
||||||
|
logger.info('post error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
5
package-lock.json
generated
5
package-lock.json
generated
@ -450,6 +450,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
||||||
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
||||||
},
|
},
|
||||||
|
"perfect-logger": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/perfect-logger/-/perfect-logger-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-MGjZ4KcKFJ0w2LOvO2kSILZMU2KUOESaIJnI4sJ6qAumEmrRHiJVPx088WgAYnZMnys6gFI2ZP2YbNTL308xkA=="
|
||||||
|
},
|
||||||
"proxy-addr": {
|
"proxy-addr": {
|
||||||
"version": "2.0.6",
|
"version": "2.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz",
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"fs": "0.0.1-security",
|
"fs": "0.0.1-security",
|
||||||
"got": "^11.1.1"
|
"got": "^11.1.1",
|
||||||
|
"perfect-logger": "^2.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
const post = require('../lib/post')
|
const post = require('../lib/post')
|
||||||
const common = require('../lib/common')
|
const common = require('../lib/common')
|
||||||
|
let logger = require('perfect-logger')
|
||||||
|
|
||||||
module.exports = function (app) {
|
module.exports = function (app) {
|
||||||
app.get("/heating", async function (req, res, next) {
|
app.get("/heating", async function (req, res, next) {
|
||||||
|
logger.info('GET - /heating - START')
|
||||||
const response = await post.postRequest('{}', 'poll')
|
const response = await post.postRequest('{}', 'poll')
|
||||||
const heating = response.updateData.zones[0]
|
const heating = response.updateData.zones[0]
|
||||||
|
logger.info('GET - /heating - END')
|
||||||
res.json(heating)
|
res.json(heating)
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/heating/status", async function (req, res, next) {
|
app.get("/heating/status", async function (req, res, next) {
|
||||||
|
logger.info('GET - /heating/status - START')
|
||||||
const response = await post.postRequest('{}', 'poll')
|
const response = await post.postRequest('{}', 'poll')
|
||||||
// console.log(response.updateData)
|
// logger.info(response.updateData)
|
||||||
const heating = response.updateData.zones[0].status
|
const heating = response.updateData.zones[0].status
|
||||||
const mrt = await common.updateTemp(heating)
|
const mrt = await common.updateTemp(heating)
|
||||||
const on = await common.heatingOn(heating)
|
const on = await common.heatingOn(heating)
|
||||||
@ -24,12 +28,15 @@ module.exports = function (app) {
|
|||||||
"lastTimerSetPoint": lsp,
|
"lastTimerSetPoint": lsp,
|
||||||
"lastTimerDurationMinutes": JSON.stringify(heating.lastTimerDurationMinutes)
|
"lastTimerDurationMinutes": JSON.stringify(heating.lastTimerDurationMinutes)
|
||||||
}
|
}
|
||||||
|
logger.info('GET - /heating/status - END')
|
||||||
res.json(heatingStatus)
|
res.json(heatingStatus)
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/heating/config", async function (req, res, next) {
|
app.get("/heating/config", async function (req, res, next) {
|
||||||
|
logger.info('GET - /heating/config - START')
|
||||||
const response = await post.postRequest('{}', 'poll')
|
const response = await post.postRequest('{}', 'poll')
|
||||||
const heating = response.updateData.zones[0].config
|
const heating = response.updateData.zones[0].config
|
||||||
|
logger.info('GET - /heating/config - END')
|
||||||
res.json(heating)
|
res.json(heating)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
const post = require('../lib/post')
|
const post = require('../lib/post')
|
||||||
const common = require('../lib/common')
|
const common = require('../lib/common')
|
||||||
|
let logger = require('perfect-logger')
|
||||||
|
|
||||||
|
|
||||||
module.exports = function (app) {
|
module.exports = function (app) {
|
||||||
app.post("/heating", async function (req, res, next) {
|
app.post("/heating", async function (req, res, next) {
|
||||||
|
logger.info('POST - /heating - START')
|
||||||
const response = await post.postRequest('{}')
|
const response = await post.postRequest('{}')
|
||||||
const heating = response.updateData.zones[0]
|
const heating = response.updateData.zones[0]
|
||||||
|
logger.info('POST - /heating - END')
|
||||||
res.json(heating)
|
res.json(heating)
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/heating/status", async function (req, res, next) {
|
app.post("/heating/status", async function (req, res, next) {
|
||||||
|
logger.info('POST - /heating/status - START')
|
||||||
const response = await post.postRequest('{}', 'poll')
|
const response = await post.postRequest('{}', 'poll')
|
||||||
const heating = response.updateData.zones[0].status
|
const heating = response.updateData.zones[0].status
|
||||||
const mrt = await common.updateTemp(heating)
|
const mrt = await common.updateTemp(heating)
|
||||||
@ -23,6 +28,7 @@ module.exports = function (app) {
|
|||||||
"lastTimerSetPoint": lsp,
|
"lastTimerSetPoint": lsp,
|
||||||
"lastTimerDurationMinutes": JSON.stringify(heating.lastTimerDurationMinutes)
|
"lastTimerDurationMinutes": JSON.stringify(heating.lastTimerDurationMinutes)
|
||||||
}
|
}
|
||||||
|
logger.info('POST - /heating/status - END')
|
||||||
res.json(heatingStatus)
|
res.json(heatingStatus)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
const post = require('../lib/post')
|
const post = require('../lib/post')
|
||||||
const common = require('../lib/common')
|
const common = require('../lib/common')
|
||||||
|
let logger = require('perfect-logger')
|
||||||
|
|
||||||
module.exports = function (app) {
|
module.exports = function (app) {
|
||||||
app.get("/water", async function (req, res, next) {
|
app.get("/water", async function (req, res, next) {
|
||||||
|
logger.info('GET - /water - START')
|
||||||
const response = await post.postRequest('{}', 'poll')
|
const response = await post.postRequest('{}', 'poll')
|
||||||
const water = response.updateData.zones[1]
|
const water = response.updateData.zones[1]
|
||||||
|
logger.info('GET - /water - END')
|
||||||
res.json(water)
|
res.json(water)
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/water/status", async function (req, res, next) {
|
app.get("/water/status", async function (req, res, next) {
|
||||||
|
logger.info('GET - /water/status - START')
|
||||||
const response = await post.postRequest('{}', 'poll')
|
const response = await post.postRequest('{}', 'poll')
|
||||||
const water = response.updateData.zones[1].status
|
const water = response.updateData.zones[1].status
|
||||||
const on = await common.heatingOn(water)
|
const on = await common.heatingOn(water)
|
||||||
@ -19,18 +23,21 @@ module.exports = function (app) {
|
|||||||
"lastTimerSetPoint": JSON.stringify(water.lastTimerSetPoint),
|
"lastTimerSetPoint": JSON.stringify(water.lastTimerSetPoint),
|
||||||
"lastTimerDurationMinutes": JSON.stringify(water.lastTimerDurationMinutes)
|
"lastTimerDurationMinutes": JSON.stringify(water.lastTimerDurationMinutes)
|
||||||
}
|
}
|
||||||
|
logger.info('GET - /water/status - END')
|
||||||
res.json(waterStatus)
|
res.json(waterStatus)
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/water/config", async function (req, res, next) {
|
app.get("/water/config", async function (req, res, next) {
|
||||||
|
logger.info('GET - /water/config - START')
|
||||||
const response = await post.postRequest('{}', 'poll')
|
const response = await post.postRequest('{}', 'poll')
|
||||||
const water = response.updateData.zones[1].config
|
const water = response.updateData.zones[1].config
|
||||||
|
logger.info('GET - /water/config - END')
|
||||||
res.json(water)
|
res.json(water)
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/water/switch", async function (req, res, next) {
|
app.get("/water/switch", async function (req, res, next) {
|
||||||
|
logger.info('GET - /water/switch - START')
|
||||||
const response = await post.postRequest('{}', 'poll')
|
const response = await post.postRequest('{}', 'poll')
|
||||||
console.log('switch status start')
|
|
||||||
const water = response.updateData.zones[1].status
|
const water = response.updateData.zones[1].status
|
||||||
let on = await common.heatingOn(water)
|
let on = await common.heatingOn(water)
|
||||||
if (on == true) {
|
if (on == true) {
|
||||||
@ -42,8 +49,8 @@ module.exports = function (app) {
|
|||||||
let switchStatus = {
|
let switchStatus = {
|
||||||
"switch": on
|
"switch": on
|
||||||
}
|
}
|
||||||
console.log(switchStatus)
|
logger.info(switchStatus)
|
||||||
console.log('switch status end')
|
logger.info('GET - /water/switch - END')
|
||||||
res.json(switchStatus)
|
res.json(switchStatus)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
const post = require('../lib/post')
|
const post = require('../lib/post')
|
||||||
const common = require('../lib/common')
|
const common = require('../lib/common')
|
||||||
|
let logger = require('perfect-logger')
|
||||||
|
|
||||||
|
|
||||||
module.exports = function (app) {
|
module.exports = function (app) {
|
||||||
app.post("/water/switch", async function (req, res, next) {
|
app.post("/water/switch", async function (req, res, next) {
|
||||||
|
logger.info('POST - /water/switch - START')
|
||||||
if (req.body.switch === 1) {
|
if (req.body.switch === 1) {
|
||||||
|
logger.info('POST - /heating/switch - ON - START')
|
||||||
try {
|
try {
|
||||||
await post.postRequest('{"zoneId":[1],"setPoint": 255,"durationMinutes": 90}', 'apply_timer')
|
await post.postRequest('{"zoneId":[1],"setPoint": 255,"durationMinutes": 90}', 'apply_timer')
|
||||||
const response = await post.postRequest('{}', 'poll')
|
const response = await post.postRequest('{}', 'poll')
|
||||||
@ -13,26 +17,34 @@ module.exports = function (app) {
|
|||||||
let waterStatus = {
|
let waterStatus = {
|
||||||
"waterOn": JSON.stringify(on),
|
"waterOn": JSON.stringify(on),
|
||||||
}
|
}
|
||||||
|
logger.info('POST - /heating/switch - ON - COMPLETE')
|
||||||
res.json(waterStatus)
|
res.json(waterStatus)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
logger.info('POST - /heating/switch - ON - FAILED')
|
||||||
}
|
}
|
||||||
} else if (req.body.switch === 0) {
|
} else if (req.body.switch === 0) {
|
||||||
await post.postRequest('{"zoneId":[1]}', 'cancel_timer')
|
try {
|
||||||
const response = await post.postRequest('{}', 'poll')
|
logger.info('POST - /heating/switch - OFF - START')
|
||||||
const water = response.updateData.zones[1].status
|
await post.postRequest('{"zoneId":[1]}', 'cancel_timer')
|
||||||
const on = await common.heatingOn(water)
|
const response = await post.postRequest('{}', 'poll')
|
||||||
|
const water = response.updateData.zones[1].status
|
||||||
|
const on = await common.heatingOn(water)
|
||||||
|
|
||||||
let waterStatus = {
|
let waterStatus = {
|
||||||
"waterOn": JSON.stringify(on),
|
"waterOn": JSON.stringify(on),
|
||||||
|
}
|
||||||
|
logger.info('POST - /heating/switch - OFF - COMPLETE')
|
||||||
|
res.json(waterStatus)
|
||||||
|
} catch (error) {
|
||||||
|
logger.info('POST - /heating/switch - OFF - FAILED')
|
||||||
}
|
}
|
||||||
res.json(waterStatus)
|
|
||||||
} else {
|
} else {
|
||||||
res.json({ "switch": "break" })
|
logger.info('POST - /heating/switch - FAILED')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/water/status", async function (req, res, next) {
|
app.post("/water/status", async function (req, res, next) {
|
||||||
|
logger.info('POST - /heating/status - START')
|
||||||
const response = await post.postRequest('{}', 'poll')
|
const response = await post.postRequest('{}', 'poll')
|
||||||
const water = response.updateData.zones[1].status
|
const water = response.updateData.zones[1].status
|
||||||
const on = await common.heatingOn(water)
|
const on = await common.heatingOn(water)
|
||||||
@ -43,6 +55,7 @@ module.exports = function (app) {
|
|||||||
"lastTimerSetPoint": JSON.stringify(water.lastTimerSetPoint),
|
"lastTimerSetPoint": JSON.stringify(water.lastTimerSetPoint),
|
||||||
"lastTimerDurationMinutes": JSON.stringify(water.lastTimerDurationMinutes)
|
"lastTimerDurationMinutes": JSON.stringify(water.lastTimerDurationMinutes)
|
||||||
}
|
}
|
||||||
|
logger.info('POST - /heating/status - END')
|
||||||
res.json(waterStatus)
|
res.json(waterStatus)
|
||||||
});
|
});
|
||||||
}
|
}
|
18
server.js
18
server.js
@ -1,13 +1,23 @@
|
|||||||
var express = require("express");
|
var express = require("express");
|
||||||
var app = express();
|
var app = express();
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
|
let logger = require('perfect-logger')
|
||||||
|
|
||||||
app.use(bodyParser.urlencoded({ extended: true }));
|
logger.initialize('FrontEndDriver', {
|
||||||
|
logLevelFile: 0, // Log level for file
|
||||||
app.use(bodyParser.json())
|
logLevelConsole: 0, // Log level for STDOUT/STDERR
|
||||||
|
logDirectory: 'logs/', // Log directory
|
||||||
|
customBannerHeaders: 'This is a custom banner' // Custom Log Banner
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use(
|
||||||
|
bodyParser.urlencoded({
|
||||||
|
extended: true
|
||||||
|
}),
|
||||||
|
bodyParser.json(),
|
||||||
|
)
|
||||||
require('./routes')(app);
|
require('./routes')(app);
|
||||||
|
|
||||||
app.listen(2020, function () {
|
app.listen(2020, function () {
|
||||||
console.log("Server running on port 2020");
|
logger.info("Server running on port 2020");
|
||||||
});
|
});
|
9
test.js
9
test.js
@ -3,18 +3,21 @@ var app = express();
|
|||||||
|
|
||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
|
|
||||||
|
const logger = require('./lib/logger')
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
bodyParser.urlencoded({
|
bodyParser.urlencoded({
|
||||||
extended: true
|
extended: true
|
||||||
})
|
}),
|
||||||
|
logger.logger
|
||||||
)
|
)
|
||||||
|
|
||||||
app.use(bodyParser.json())
|
app.use(bodyParser.json())
|
||||||
|
|
||||||
app.post('/endpoint', (req, res) => {
|
app.post('/endpoint', (req, res) => {
|
||||||
console.log(req.body)
|
logger.info(req.body)
|
||||||
})
|
})
|
||||||
|
|
||||||
app.listen(2020, function () {
|
app.listen(2020, function () {
|
||||||
console.log("Server running on port 2020");
|
logger.info("Server running on port 2020");
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user