Commit 03397e7d16391375bf222f3710cdd068c182d0b2
1 parent
69192450
Exists in
master
and in
1 other branch
sistema de log"
Showing
6 changed files
with
174 additions
and
3 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | +{ | |
| 2 | + "resumo": { | |
| 3 | + "bloqueante": { | |
| 4 | + "1": 1, | |
| 5 | + "2": 0, | |
| 6 | + "3": 0, | |
| 7 | + "4": 0 | |
| 8 | + }, | |
| 9 | + "nao-bloqueante": { | |
| 10 | + "1": 0, | |
| 11 | + "2": 0, | |
| 12 | + "3": 0, | |
| 13 | + "4": 0 | |
| 14 | + } | |
| 15 | + }, | |
| 16 | + "detalhado": { | |
| 17 | + "1": "detalhe do erro", | |
| 18 | + "2": "detalhe", | |
| 19 | + "3": "detalhe", | |
| 20 | + "4": "detalhe" | |
| 21 | + } | |
| 22 | +} | |
| 0 | 23 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +{ | |
| 2 | + "resumo": { | |
| 3 | + "bloqueante": { | |
| 4 | + "1": 0, | |
| 5 | + "2": 0, | |
| 6 | + "3": 0, | |
| 7 | + "4": 0 | |
| 8 | + }, | |
| 9 | + "nao-bloqueante": { | |
| 10 | + "1": 0, | |
| 11 | + "2": 0, | |
| 12 | + "3": 0, | |
| 13 | + "4": 0 | |
| 14 | + } | |
| 15 | + }, | |
| 16 | + "detalhado": { | |
| 17 | + "1": "detalhe", | |
| 18 | + "2": "detalhe", | |
| 19 | + "3": "detalhe", | |
| 20 | + "4": "detalhe" | |
| 21 | + | |
| 22 | + } | |
| 23 | +} | ... | ... |
logsystem/main.coffee
| 1 | -config = require('./config/main.js') | |
| 1 | +config = require('../config/main.js') | |
| 2 | +fs = require('fs') | |
| 3 | +kue = require('kue') | |
| 4 | +queue = kue.createQueue() | |
| 5 | +exports = module.exports = {} | |
| 6 | + | |
| 7 | +# 1 - Core retornou um erro. | |
| 8 | +# 2 - Vídeo inválido. | |
| 9 | +# 3 - Legenda inválida. | |
| 10 | +# 4 - Endpoint inválido. | |
| 11 | + | |
| 12 | +# params_box = JSON.parse(fs.readFileSync('./config/params_box.json', 'utf8')) | |
| 13 | +# errors = JSON.parse(fs.readFileSync('./logsystem/errors.log', 'utf8')) | |
| 14 | +# services = JSON.parse(fs.readFileSync('./logsystem/services.log', 'utf8')) | |
| 15 | + | |
| 16 | + | |
| 17 | +writeLog = (file, path) -> | |
| 18 | + fs.writeFileSync path, JSON.stringify(file, null, 4) | |
| 19 | + | |
| 20 | + | |
| 21 | +exports.incrementError = (id, detalhe="", inc=1) -> | |
| 22 | + errors_log_path = "./logsystem/errors.log" | |
| 23 | + errors = JSON.parse(fs.readFileSync(errors_log_path, 'utf8')) | |
| 24 | + | |
| 25 | + bloqueante = !config.isNaoBloqueante() # diferente de nao bloqueante aceita bloqueante ou ambos | |
| 26 | + | |
| 27 | + # id pode ser "1", "2", "3", "4" ou qualquer outro id criado para identificar erros | |
| 28 | + # 1 - Core retornou um erro. | |
| 29 | + # 2 - Vídeo inválido. | |
| 30 | + # 3 - Legenda inválida. | |
| 31 | + # 4 - Endpoint inválido. | |
| 32 | + | |
| 33 | + if bloqueante | |
| 34 | + errors["resumo"]["bloqueante"][id] += inc | |
| 35 | + else | |
| 36 | + errors["resumo"]["nao-bloqueante"][id] += inc | |
| 37 | + | |
| 38 | + errors["detalhado"][id] = detalhe | |
| 39 | + | |
| 40 | + writeLog(errors, errors_log_path) | |
| 41 | + | |
| 42 | +exports.incrementService = (serviceType, type, inc=1) -> | |
| 43 | + services_log_path = "./logsystem/services.log" | |
| 44 | + services = JSON.parse(fs.readFileSync(services_log_path, 'utf8')) | |
| 45 | + | |
| 46 | + if serviceType == "videos" | |
| 47 | + services["tipo"]["videos"][type] += inc | |
| 48 | + else if serviceType == "outros" | |
| 49 | + services["tipo"]["outros"][type] += inc | |
| 50 | + | |
| 51 | + | |
| 52 | + writeLog(services, services_log_path) | ... | ... |
logsystem/main.js
| 1 | 1 | (function() { |
| 2 | - var config; | |
| 2 | + var config, exports, fs, kue, queue, writeLog; | |
| 3 | 3 | |
| 4 | - config = require('./config/main.js'); | |
| 4 | + config = require('../config/main.js'); | |
| 5 | + | |
| 6 | + fs = require('fs'); | |
| 7 | + | |
| 8 | + kue = require('kue'); | |
| 9 | + | |
| 10 | + queue = kue.createQueue(); | |
| 11 | + | |
| 12 | + exports = module.exports = {}; | |
| 13 | + | |
| 14 | + writeLog = function(file, path) { | |
| 15 | + return fs.writeFileSync(path, JSON.stringify(file, null, 4)); | |
| 16 | + }; | |
| 17 | + | |
| 18 | + exports.incrementError = function(id, detalhe, inc) { | |
| 19 | + var bloqueante, errors, errors_log_path; | |
| 20 | + if (detalhe == null) { | |
| 21 | + detalhe = ""; | |
| 22 | + } | |
| 23 | + if (inc == null) { | |
| 24 | + inc = 1; | |
| 25 | + } | |
| 26 | + errors_log_path = "./logsystem/errors.log"; | |
| 27 | + errors = JSON.parse(fs.readFileSync(errors_log_path, 'utf8')); | |
| 28 | + bloqueante = !config.isNaoBloqueante(); | |
| 29 | + if (bloqueante) { | |
| 30 | + errors["resumo"]["bloqueante"][id] += inc; | |
| 31 | + } else { | |
| 32 | + errors["resumo"]["nao-bloqueante"][id] += inc; | |
| 33 | + } | |
| 34 | + errors["detalhado"][id] = detalhe; | |
| 35 | + return writeLog(errors, errors_log_path); | |
| 36 | + }; | |
| 37 | + | |
| 38 | + exports.incrementService = function(serviceType, type, inc) { | |
| 39 | + var services, services_log_path; | |
| 40 | + if (inc == null) { | |
| 41 | + inc = 1; | |
| 42 | + } | |
| 43 | + services_log_path = "./logsystem/services.log"; | |
| 44 | + services = JSON.parse(fs.readFileSync(services_log_path, 'utf8')); | |
| 45 | + if (serviceType === "videos") { | |
| 46 | + services["tipo"]["videos"][type] += inc; | |
| 47 | + } else if (serviceType === "outros") { | |
| 48 | + services["tipo"]["outros"][type] += inc; | |
| 49 | + } | |
| 50 | + return writeLog(services, services_log_path); | |
| 51 | + }; | |
| 5 | 52 | |
| 6 | 53 | }).call(this); | ... | ... |