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

Release #29

Merged
merged 5 commits into from
Jan 11, 2024
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# [1.2.0-release.1](https://github.com/tbvgl/wappler-advanced-logger/compare/v1.1.5-release.1...v1.2.0-release.1) (2024-01-11)


### Features

* allow for additional log data ([144971c](https://github.com/tbvgl/wappler-advanced-logger/commit/144971cdbbd94cedb9a7ce68e0293c5e174d3749))

## [1.1.5-release.1](https://github.com/tbvgl/wappler-advanced-logger/compare/v1.1.4...v1.1.5-release.1) (2023-10-19)

## [1.1.5](https://github.com/tbvgl/wappler-advanced-logger/compare/v1.1.4...v1.1.5) (2023-10-19)


Expand Down
31 changes: 30 additions & 1 deletion server_connect/modules/advanced-logger.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"name": "actionName",
"optionName": "name",
"title": "Name",
"baseName": "log",
"type": "text",
"required": true,
"defaultValue": ""
Expand Down Expand Up @@ -52,7 +53,35 @@
"required": true,
"serverDataBindings": true,
"help": "The log level"
}
},
{
"name": "bindings",
"optionName": "bindings",
"key": "var",
"keyValue": "value",
"title": "Additional Data",
"type": "grid",
"defaultValue": {},
"serverDataBindings": true,
"columns": [
{
"field": "var",
"caption": "Variable",
"size": "30%",
"editable": {
"type": "text"
}
},
{
"field": "value",
"caption": "Value",
"size": "70%",
"editable": {
"type": "datapicker"
}
}
]
},
]
}
]
Expand Down
37 changes: 34 additions & 3 deletions server_connect/modules/advanced-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ const logDirectoryPath = process.env.LOG_FILE_PATH
? toSystemPath(process.env.LOG_FILE_PATH)
: null;
const minLength = process.env.WRITE_LOG_MIN_LENGTH || 4096;
let Sentry;
const sentryDsn = process.env.SENTRY_DSN;

if (sentryDsn) {
Sentry = require("@sentry/node");
Sentry.init({ dsn: sentryDsn });
}

const transports = [];

Expand Down Expand Up @@ -46,6 +53,7 @@ if (logFilePath) {
}

const transport = pino.transport({ targets: transports });

const logger = pino(
{
level: logLevel,
Expand All @@ -69,6 +77,7 @@ function getCurrentDate() {
function parse(options) {
options = options || {};
let details = null;
let bindings = options.bindings || {};

if (options.details) {
if (typeof options.details === "string") {
Expand All @@ -88,6 +97,7 @@ function parse(options) {
message: message,
log_level: options.log_level || "info",
details,
bindings
};
}
async function cleanOldLogs(options) {
Expand Down Expand Up @@ -138,8 +148,9 @@ async function cleanOldLogs(options) {
async function logMessage(options) {
options =
typeof this.parse === "function" ? this.parse(options) : parse(options);
const { message, log_level, details } = options || {};

const { message, log_level, details, bindings } = options || {};


if (!message) {
return;
}
Expand All @@ -148,20 +159,31 @@ async function logMessage(options) {
message,
log_level,
details,
...bindings
};

if (!prettyPrint && logEnvironment) {
logObject.log_environment = logEnvironment;
}

// Log to Sentry regardless of log_level
if (sentryDsn) {
Sentry.captureMessage(message, {
level: log_level,
extra: logObject,
tags: { details: JSON.stringify(details) },
});
}

// Log to other destinations for all log levels
logger[log_level](logObject);

}

function logMessageSync(options) {
options =
typeof this.parse === "function" ? this.parse(options) : parse(options);
const { message, log_level, details } = options || {};
const { message, log_level, details} = options || {};

if (!message) {
return;
Expand All @@ -171,12 +193,21 @@ function logMessageSync(options) {
message,
log_level,
details,
...bindings
};

if (!prettyPrint && logEnvironment) {
logObject.log_environment = logEnvironment;
}

// Log to Sentry regardless of log_level
if (sentryDsn) {
Sentry.captureMessage(message, {
level: log_level,
extra: logObject,
tags: { details: JSON.stringify(details) },
});
}

// Log to other destinations for all log levels
logger[log_level](logObject);
Expand Down
Loading