Skip to content

Commit

Permalink
Merge branch 'main' into feature/service-commander
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjulaGanepola authored Sep 19, 2024
2 parents ecaddd2 + d9a928b commit e0683fe
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 37 deletions.
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [Manzan](config/app.md)
* [Data Sources](config/data.md)
* [Destinations](config/dests.md)
* [Logging](config/logging.md)
* Examples
* [File](config/examples/file.md)
* [Twilio](config/examples/twilio.md)
Expand Down
22 changes: 22 additions & 0 deletions docs/config/logging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Logging

### Log Levels

Manzan has three options for available logging levels which can be configured via the `MANZAN_DEBUG_LEVEL` system environment variable.

* `MANZAN_DEBUG_LEVEL = 0`: Do not log any messages
* `MANZAN_DEBUG_LEVEL = 1`: Log only errors
* `MANZAN_DEBUG_LEVEL = 2`: Log errors and warnings
* `MANZAN_DEBUG_LEVEL = 3`: Log errors, warnings, and info

Logs will be written to `/tmp/manzan_debug.txt`.

### Setting the Log Level

The `MANZAN_DEBUG_LEVEL` environment variable can be set with the `ADDENVVAR` command. For example, to log errors, warnings, and info messages use:

```cl
ADDENVVAR ENVVAR(MANZAN_DEBUG_LEVEL) VALUE(3) LEVEL(*SYS) REPLACE(*YES)
```

After which you will need to run `ENDTCPSVR *SSHD` and `STRTCPSVR *SSHD`. Then restart your SSH session for the new environment variable to take effect.
49 changes: 41 additions & 8 deletions ile/src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

FILE *debug_fd = NULL;

Expand All @@ -25,16 +26,48 @@ extern "C" void ENDDBG()
#endif
}

extern "C" void DEBUG(const char *format, ...)
{


// Helper function to handle the common logic
extern "C" void DEBUG_LOG(const char *level, const char *label, const char *format, va_list args) {
#ifdef DEBUG_ENABLED
char *env_level = getenv("MANZAN_DEBUG_LEVEL");
if (env_level == NULL){
env_level = "2"; // Show errors and warnings only
}
if (strcmp(env_level, level) >= 0 && debug_fd != NULL) {
fprintf(debug_fd, "%s ", label); // Prepend the log level
vfprintf(debug_fd, format, args);
fflush(debug_fd);
}
#endif
}

// Wrapper functions for different debug levels

extern "C" void DEBUG_INFO(const char *format, ...) {
#ifdef DEBUG_ENABLED
if (NULL != debug_fd)
{
va_list args;
va_start(args, format);
vfprintf(debug_fd, format, args);
DEBUG_LOG("3", "[INFO]", format, args);
va_end(args);
#endif
}

extern "C" void DEBUG_WARNING(const char *format, ...) {
#ifdef DEBUG_ENABLED
va_list args;
va_start(args, format);
DEBUG_LOG("2", "[WARNING]", format, args);
va_end(args);
fflush(debug_fd);
}
#endif
}
}

extern "C" void DEBUG_ERROR(const char *format, ...) {
#ifdef DEBUG_ENABLED
va_list args;
va_start(args, format);
DEBUG_LOG("1", "ERROR", format, args);
va_end(args);
#endif
}
38 changes: 19 additions & 19 deletions ile/src/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,18 @@ int main(int _argc, char **argv)
BUFSTRN(watch_option, argv[1], 10);
BUFSTRN(session_id, argv[2], 10);

DEBUG("Watch program called. Watch option setting is '%s'\n", watch_option.c_str());
DEBUG_INFO("Watch program called. Watch option setting is '%s'\n", watch_option.c_str());
publisher_info_set *publishers = conf_get_publisher_info(session_id.c_str());
int num_publishers = publishers->num_publishers;
if (0 == num_publishers)
{
DEBUG("No publishers found for watch option '%s' and session ID '%s'\n", watch_option.c_str(), session_id.c_str());
DEBUG_ERROR("No publishers found for watch option '%s' and session ID '%s'\n", watch_option.c_str(), session_id.c_str());
ENDDBG();
return 0;
}
if (watch_option == "*MSGID")
{
DEBUG("Handling message\n");
DEBUG_INFO("Handling message\n");
msg_event_raw *msg_event = (msg_event_raw *)argv[4];
BUFSTR(msgid, msg_event->message_watched);
BUFSTR(job_name, msg_event->job_name);
Expand All @@ -113,7 +113,7 @@ int main(int _argc, char **argv)
std::string job = job_number + "/" + user_name + "/" + job_name;
BUFSTR(message_type, msg_event->message_type);
std::string message_timestamp = get_iso8601_timestamp(msg_event->message_timestamp);
DEBUG("Timestamp is '%s'\n", message_timestamp.c_str());
DEBUG_INFO("Timestamp is '%s'\n", message_timestamp.c_str());
int message_severity = msg_event->message_severity;
BUFSTR(sending_usrprf, msg_event->sending_user_profile);
BUFSTRN(sending_procedure_name, (char *)msg_event + msg_event->offset_send_procedure_name, msg_event->length_send_procedure_name);
Expand All @@ -123,17 +123,17 @@ int main(int _argc, char **argv)

int replacement_data_offset = msg_event->offset_replacement_data;
int replacement_data_len = msg_event->length_replacement_data;
DEBUG("Replacement data offset is '%d'\n", replacement_data_offset);
DEBUG("REPLACEMENT DATA LENGTH IS '%d'\n", replacement_data_len);
DEBUG_INFO("Replacement data offset is '%d'\n", replacement_data_offset);
DEBUG_INFO("REPLACEMENT DATA LENGTH IS '%d'\n", replacement_data_len);
char message_watched[8];
message_watched[7] = 0x00;
memcpy(message_watched, msg_event->message_watched, 7);
DEBUG("MESSAGE WATCHED IS '%s'\n", message_watched);
DEBUG_INFO("MESSAGE WATCHED IS '%s'\n", message_watched);
char qualified_msg_file[21];
qualified_msg_file[20] = 0x00;
memcpy(qualified_msg_file, msg_event->message_file_name, 10);
memcpy(qualified_msg_file + 10, msg_event->message_file_library, 10);
DEBUG("MESSAGE FILE AND NAME IS '%s'\n", qualified_msg_file);
memcpy(qualified_msg_file+10, msg_event->message_file_library, 10);
DEBUG_INFO("MESSAGE FILE AND NAME IS '%s'\n", qualified_msg_file);
char *replacement_data = (0 == replacement_data_len) ? (char *)"" : (((char *)msg_event) + replacement_data_offset);
char *replacement_data_aligned = (char *)malloc(1 + replacement_data_len);
memset(replacement_data_aligned, 0x00, 1 + replacement_data_len);
Expand All @@ -144,14 +144,14 @@ int main(int _argc, char **argv)
memset(msg_info_buf, 0x00, msg_info_buf_size);
if (' ' == qualified_msg_file[0])
{
DEBUG("Message not from message file\n");
DEBUG_INFO("Message not from message file\n");
strncpy(msg_info_buf->message, replacement_data_aligned, replacement_data_len);
}
else
{
char err_plc[64];
memset(err_plc, 0x00, sizeof(err_plc));
DEBUG("About to format...\n");
DEBUG_INFO("About to format...\n");

QMHRTVM(
// 1 Message information Output Char(*)
Expand All @@ -174,11 +174,11 @@ int main(int _argc, char **argv)
"*NO ",
// 10 Error code I/O Char(*)
err_plc);
DEBUG("Done formatting \n");
DEBUG("The full message is '%s'\n", msg_info_buf->message);
DEBUG_INFO("Done formatting \n");
DEBUG_INFO("The full message is '%s'\n", msg_info_buf->message);
}
free(replacement_data_aligned);
DEBUG("About to publish...\n");
DEBUG_INFO("About to publish...\n");
for (int i = 0; i < num_publishers; i++)
{
msg_publish_func func = publishers->array[i].msg_publish_func_ptr;
Expand All @@ -194,15 +194,15 @@ int main(int _argc, char **argv)
sending_program_name.c_str(),
sending_module_name.c_str(),
sending_procedure_name.c_str());
DEBUG("Published\n");
DEBUG_INFO("Published\n");
}
free(msg_info_buf);
memset(argv[3], ' ', 10);
DEBUG("DONE\n");
DEBUG_INFO("DONE\n");
}
else if (watch_option == "*LICLOG")
{
DEBUG("Handling LIC log\n");
DEBUG_INFO("Handling LIC log\n");
vlog_event_raw *lic_event = (vlog_event_raw *)argv[4];
BUFSTR(major_code, lic_event->lic_log_major_code);
BUFSTR(minor_code, lic_event->lic_log_minor_code);
Expand Down Expand Up @@ -245,7 +245,7 @@ int main(int _argc, char **argv)
}
else if (watch_option == "*PAL")
{
DEBUG("Handling PAL Entry\n");
DEBUG_INFO("Handling PAL Entry\n");
pal_event_raw *pal_event = (pal_event_raw *)argv[4];
BUFSTR(system_reference_code, pal_event->system_reference_code);
BUFSTR(device_name, pal_event->device_name);
Expand Down Expand Up @@ -293,7 +293,7 @@ int main(int _argc, char **argv)
printf("Well, shit\n");
if (4 <= _argc)
strncpy(argv[3], "*ERROR ", 10);
DEBUG("MCH exception happened!\n");
DEBUG_ERROR("MCH exception happened!\n");
ENDDBG();
return 1;
}
5 changes: 4 additions & 1 deletion ile/src/manzan.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ extern "C"
#endif
extern void STRDBG();
extern void ENDDBG();
extern void DEBUG(const char *format, ...);
extern void DEBUG_INFO(const char *format, ...);
extern void DEBUG_WARNING(const char *format, ...);
extern void DEBUG_ERROR(const char *format, ...);


#define DEBUG_ENABLED 1

Expand Down
6 changes: 3 additions & 3 deletions ile/src/pub_db2.sqlc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ void check_sql_error(int sqlcode, const char* sqlstate)
{
if (sqlcode != 0)
{
DEBUG("SQL Code: %d\n", sqlcode);
DEBUG("SQL State: %s\n", sqlstate);
DEBUG_ERROR("SQL Code: %d\n", sqlcode);
DEBUG_ERROR("SQL State: %s\n", sqlstate);
}
else
{
DEBUG("SQL statement executed succesfully!\n");
DEBUG_INFO("SQL statement executed succesfully!\n");
}
}

Expand Down
12 changes: 6 additions & 6 deletions ile/src/pub_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int to_utf8(char *out, size_t out_len, const char *in)
int rc = iconv(cd, &input, &inleft, &output, &outleft);
if (rc == -1)
{
DEBUG("Error in converting characters\n");
DEBUG_ERROR("Error in converting characters\n");
return 9;
}
return iconv_close(cd);
Expand Down Expand Up @@ -97,8 +97,8 @@ int json_publish(const char *_session_id, std::string &_json)
char *utf8 = (char *)malloc(56 + _json.length() * 2);

to_utf8(utf8, json_len, _json.c_str());
DEBUG("Publishing JSON\n");
DEBUG("%s\n", _json.c_str());
DEBUG_INFO("Publishing JSON\n");
DEBUG_INFO("%s\n", _json.c_str());

__attribute__((aligned(16))) char dtaq_key[11];
memset(dtaq_key, ' ', 11);
Expand All @@ -108,16 +108,16 @@ int json_publish(const char *_session_id, std::string &_json)
len2 += strlen(utf8);
_DecimalT<3,0> keyLen = __D("10.0");

DEBUG("About to call QSNDDTAQ\n");
DEBUG_INFO("About to call QSNDDTAQ\n");
QSNDDTAQ("MANZANDTAQ",
"MANZAN ", // TODO: How to properly resolve the library here?
len2,
utf8,
keyLen,
&dtaq_key);
DEBUG("About to free up stuff\n");
DEBUG_INFO("About to free up stuff\n");
free(utf8);
DEBUG("Done publishing JSON\n");
DEBUG_INFO("Done publishing JSON\n");
return 0;
}

Expand Down
Empty file modified scripts/buildAll.sh
100644 → 100755
Empty file.
Empty file modified scripts/buildAllAndTestE2e.sh
100644 → 100755
Empty file.
Empty file modified scripts/buildCamel.sh
100644 → 100755
Empty file.
Empty file modified scripts/buildCamelAndTestE2e.sh
100644 → 100755
Empty file.
Empty file modified scripts/buildIle.sh
100644 → 100755
Empty file.
Empty file modified scripts/deploy.sh
100644 → 100755
Empty file.
Empty file modified scripts/testE2e.sh
100644 → 100755
Empty file.
Empty file modified scripts/testIle.sh
100644 → 100755
Empty file.

0 comments on commit e0683fe

Please sign in to comment.