diff options
author | Alex Shatov <alexs@att.com> | 2017-09-15 13:52:31 -0400 |
---|---|---|
committer | Alex Shatov <alexs@att.com> | 2017-09-15 13:52:31 -0400 |
commit | b511ff360603599c43e066722d3902a55fac3f6d (patch) | |
tree | 7caa5c8ceb51568b444f0bd4ed9158fe92e8355e /lib/logging.js | |
parent | 3486bd1a77a8a3f198de171fda34c102406a26ea (diff) |
4.2.0 - added the policy-update handling
* API version 4.1.0 - added /policy, /swagger-ui
* new: policy update with queuing of execute-operations
* more data on info - branch+commit-datetime
* expecting consul ip to be in /etc/hosts
* added swagger-ui and added policy to *API.yaml
* common logging - more audits and metrics records
- directly in promise_request
Change-Id: I7d32f34100a16b5b7293ed5afe67f5c8c3098495
Issue-Id: DCAEGEN2-62
Signed-off-by: Alex Shatov <alexs@att.com>
Diffstat (limited to 'lib/logging.js')
-rw-r--r-- | lib/logging.js | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/lib/logging.js b/lib/logging.js index 5bfd48a..4d85898 100644 --- a/lib/logging.js +++ b/lib/logging.js @@ -1,16 +1,16 @@ /* -Copyright(c) 2017 AT&T Intellectual Property. All rights reserved. +Copyright(c) 2017 AT&T Intellectual Property. All rights reserved. -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -CONDITIONS OF ANY KIND, either express or implied. +CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ @@ -71,16 +71,17 @@ const ERROR_NFIELDS = 11; /* Error code -> description mapping */ const descriptions = { - + 201: 'Inventory communication error', 202: 'Cloudify Manager communication error', - + 501: 'Inventory API error', 502: 'Cloudify Manager API error', - + 551: 'HTTP(S) Server initialization error', 552: 'Dispatcher start-up error', - + 553: 'Execute workflow on deployment error', + 999: 'Unknown error' }; @@ -122,7 +123,7 @@ const DEBUG_REQID = 1; const DEBUG_INFO = 2; const DEBUG_EOR = 3; const DEBUG_NFIELDS = 4; -const DEBUG_MARKER = '^\n'; +const DEBUG_MARKER = '^'; /* Format audit record for an incoming API request */ @@ -141,7 +142,7 @@ const formatAuditRecord = function(req, status, extra) { rec[AUDIT_ELAPSED] = end - req.startTime; rec[AUDIT_SERVER] = req.hostname // From the Host header, again rec[AUDIT_CLIENTIP] = req.connection.remoteAddress; - + if (extra) { rec[AUDIT_DETAILMSG]= extra.replace(/\n/g, " "); /* Collapse multi-line extra data to a single line */ } @@ -162,7 +163,7 @@ const formatMetricsRecord = function(req, opInfo, extra) { const end = new Date(); rec[METRICS_END] = end.toISOString(); rec[METRICS_BEGIN] = opInfo.startTime.toISOString(); - + /* If reporting on a suboperation invoked as a result of an incoming request, capture info about that request */ if (req) { rec[METRICS_REQID] = req.dcaeReqId; @@ -174,14 +175,14 @@ const formatMetricsRecord = function(req, opInfo, extra) { else { /* No incoming request */ rec[METRICS_REQID] = 'no incoming request'; - rec[METRICS_SRVNAME] = os.hostname(); + rec[METRICS_SRVNAME] = os.hostname(); rec[METRICS_SVCNAME] = 'no incoming request'; } - + rec[METRICS_TGTENTITY] = opInfo.targetEntity; rec[METRICS_TGTSVC] = opInfo.targetService; rec[METRICS_STATUSCODE] = opInfo.complete ? "COMPLETE" : "ERROR"; - rec[METRICS_RESPCODE] = opInfo.respCode; + rec[METRICS_RESPCODE] = opInfo.respCode; rec[METRICS_CATLOGLEVEL] = "INFO"; // The audit records are informational, regardless of the outcome of the operation rec[METRICS_ELAPSED] = end - opInfo.startTime; @@ -196,25 +197,25 @@ const formatMetricsRecord = function(req, opInfo, extra) { /* Format error log record */ const formatErrorRecord = function(category, code, detail, req, target) { var rec = new Array(ERROR_NFIELDS); - + /* Common fields */ rec[ERROR_TIMESTAMP] = (new Date()).toISOString(); rec[ERROR_CATEGORY] = category; rec[ERROR_CODE] = code; rec[ERROR_DESCRIPTION] = descriptions[code] || 'no description available'; - + /* Log error detail in a single line if provided */ if (detail) { rec[ERROR_MESSAGE] = detail.replace(/\n/g, " "); } - + /* Fields available if the error happened during processing of an incoming API request */ if (req) { rec[ERROR_REQID] = req.dcaeReqId; rec[ERROR_SVCNAME] = req.method + ' ' + req.originalUrl; // Method and URL identify the operation being performed - rec[ERROR_PARTNER] = req.connection.remoteAddress; // We don't have the partner's name, but we know the remote IP address + rec[ERROR_PARTNER] = req.connection.remoteAddress; // We don't have the partner's name, but we know the remote IP address } - + /* Include information about the target entity/service if available */ if (target) { rec[ERROR_TGTENTITY] = target.entity || ''; @@ -226,35 +227,35 @@ const formatErrorRecord = function(category, code, detail, req, target) { /* Format debug log record */ const formatDebugRecord = function(reqId, msg) { var rec = new Array(DEBUG_NFIELDS); - + rec[DEBUG_TIMESTAMP] = new Date().toISOString(); rec[DEBUG_REQID] = reqId || ''; rec[DEBUG_INFO] = msg; rec[DEBUG_EOR] = DEBUG_MARKER; - + return rec.join('|'); }; exports.getLogger = function() { return { - + audit: function(req, status, extra) { auditLogger.info(formatAuditRecord(req, status, extra)); }, - + error: function(error, req) { errorLogger.error(formatErrorRecord("ERROR", error.logCode, error.message, req, {entity: error.target})); }, - + warn: function(error, req) { errorLogger.error(formatErrorRecord("WARN", error.logCode, error.message, req, {entity: error.target})); }, - + metrics: function(req, opInfo, extra) { metricsLogger.info(formatMetricsRecord(req, opInfo, extra)); }, - + debug: function(reqId, msg) { debugLogger.debug(formatDebugRecord(reqId, msg)); } |