Skip to content

Commit

Permalink
Merge pull request #4 from mateusfg7/log_rules > close #1
Browse files Browse the repository at this point in the history
Log rules
  • Loading branch information
mateusfg7 committed Jun 8, 2020
2 parents cc74ac5 + 4c3151b commit 28ec30f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ yarn.lock

# database
*.db

#logs
log*
14 changes: 14 additions & 0 deletions src/log/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function showAndSaveLog(log_text, hour) {
const string = `[${hour}] ${log_text}`

const filesystem = require('fs')
filesystem.writeFile('src/log/logs.txt', string+'\n', {flag: 'a'}, function (err) {
if(err) {
throw err
}
})

console.log(string)
}

module.exports = showAndSaveLog
20 changes: 17 additions & 3 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const showAndSaveLog = require("./log/log")
const now = () => {
const dateClass = new Date
const date_hour = `${dateClass.getDay()}/${dateClass.getMonth()}/${dateClass.getFullYear()}-${dateClass.getHours()}:${dateClass.getMinutes()}:${dateClass.getSeconds()}`
return date_hour
}


const express = require("express");
const server = express();

Expand All @@ -22,13 +30,14 @@ nunjucks.configure("src/views/", {
// req: resquisition
// res: response
server.get("/", (req, res) => {
showAndSaveLog('rendering index.html', now())
return res.render("index.html");
});

server.get("/create-point", (req, res) => {
// query strings
// console.log(req.query)

showAndSaveLog('rendering create-point.html', now())
return res.render("create-point.html");
});

Expand Down Expand Up @@ -57,16 +66,19 @@ server.post("/savepoint", (req, res) => {
req.body.city,
req.body.items,
];


showAndSaveLog('registering point', now())
db.run(query, values, function (err) {
if (err) {
showAndSaveLog('error when registering point', now())
console.log(err);
return res.send("Erro no cadastro");
}

console.log("[personal] data registered in database");
showAndSaveLog('data registered in database', now())
console.log(this);

showAndSaveLog('rendering create-point.html', now())
return res.render("create-point.html", { saved: true });
});
});
Expand All @@ -76,6 +88,7 @@ server.get("/search-results", (req, res) => {

if (search == "") {
// empity search
showAndSaveLog('rendering search-results.html', now())
return res.render("search-results.html", { total: 0 });
}

Expand All @@ -86,6 +99,7 @@ server.get("/search-results", (req, res) => {
}

// shows the HTML page with the datas of database
showAndSaveLog('rendering search-results.html', now())
return res.render("search-results.html", {
places: rows,
total: rows.length,
Expand Down

0 comments on commit 28ec30f

Please sign in to comment.