Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log rules #4

Merged
merged 7 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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