rxnt-node-logger
v1.0.7
Published
Node middleware for RxNT that takes an error object and sends it to a remote endpoint
Downloads
1,058
Readme
rxnt-node-logger
This project is configured to send logs from rxnt node apis to fluentd.
Install
npm install --save rxnt-node-logger
Options
The package exposes a log function that takes and error object, application environment, and a callback function that handles logging in case the api fails. Based on the environment, it will send the logs to different environment.
The log function takes arguments in following order:
- error object - The actual error object the follows the predefined error model
- application environment - A string values that determines the current application environment
- logger callback - A function that will be called to save the logs in the local sotrage in case the api call fails
Usage
const rxntLogger = require('rxnt-node-logger');
let error = {
logger: "RxntBaseClasses.ExceptionLogger.Logger",
level: err.level ? err.level : "warn",
user: "TemplateEngineAPI",
host: `${config.host}`,
logtime: new Date().toLocaleString(),
http: {
session_id: req.sessionId,
http_method: req.method,
url: req.url,
url_referrer: req.headers.referer,
user_agent: req.headers["user-agent"],
user_host_address: req.headers.host,
request_headers: req.headers,
form_params: []
},
rxnt: {
Application: `${config.application}`,
HostedId: `${config.host}:${config.port}`,
Message: err.message,
Source: err.source,
StackTrace: err.stackTrace,
DoctorCompanyId: req.headers.doctorcompanyid,
CompanyTypeId: err.companyTypeId,
DoctorGroupId: req.headers.doctorgroupid,
DoctorId: req.headers.doctorgroupid,
LoggedInUserId: err.loggedInUserId,
CreatedBy: err.createdBy,
PrimaryKey: err.primaryKey, //primaryky
OwnerType: err.ownerType,
Token: req.headers.token,
Signature: req.headers.signature,
ExternalDoctorCompanyId: err.externalDoctorCompanyId,
ExternalAppLoginId: err.externalAppLoginId,
ConsumerIP: (req.connection !== undefined && req.connection !== null ? req.connection.remoteAddress : ''),
ExternalApplicationName: err.externalApplicationName,
OtherInfo: err.otherInfo,
}
}
let localAppLogger = () {
// code to handle logs in case the api service fails
}
// call the api with the error objectt, app environment and callback function in case the send api fails
rxntLogger.log(errObject, process.env.DeploymentEnv, localAppLogger);