log: function (filename, text) { // filename now() + text var s = utils.digitime() + ' ' + text + '\n'; // utils.digitime() - - .. :: fs.open(LOG_PATH + filename, "a", 0x1a4, function (error, file_handle) { if (!error) { fs.write(file_handle, s, null, 'utf8', function (err) { if (err) { console.log(ERR_UTILS_FILE_WRITE + filename + ' ' + err); } fs.close(file_handle, function () { callback(); }); }); } else { console.log(ERR_UTILS_FILE_OPEN + filename + ' ' + error); callback(); } }); }
__log = function (filename, text) { return function (callback) { var s = utils.digitime() + ' ' + text + '\n'; fs.open(LOG_PATH + filename, "a", 0x1a4, function (error, file_handle) { if (!error) { fs.write(file_handle, s, null, 'utf8', function (err) { if (err) { console.log(ERR_UTILS_FILE_WRITE + filename + ' ' + err); } fs.close(file_handle, function () { callback(); }); }); } else { console.log(ERR_UTILS_FILE_OPEN + filename + ' ' + error); callback(); } }); }; };
__writeQueue = async.queue(function (task, callback) { task(callback); }, MAX_OPEN_FILES);
log: function (filename, text) { __writeQueue.push(__log(filename, text)); },
function errorNotFound (req, res) { utils.log(LOG_404, '' + req.method + '\t' + req.url + '\t(' + (accepts) + ')\t requested from ' + utils.getClientAddress(req)); ..
Source: https://habr.com/ru/post/158329/
All Articles