-
Notifications
You must be signed in to change notification settings - Fork 0
feat: install the SolidSyslog error handler #29
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* See SyslogErrorHandler.h. Prints to the same console as the rest of the | ||
| * device, so a fault shows up in the run report next to everything else. */ | ||
|
|
||
| #include "SyslogErrorHandler.h" | ||
|
|
||
| #include "SolidSyslogError.h" | ||
| #include "SolidSyslogErrorCategory.h" | ||
| #include "SolidSyslogPrival.h" | ||
|
|
||
| #include <stdint.h> | ||
| #include <stdio.h> | ||
|
|
||
| static const char* SeverityName(enum SolidSyslogSeverity severity) | ||
| { | ||
| switch (severity) | ||
| { | ||
| case SOLIDSYSLOG_SEVERITY_EMERGENCY: | ||
| return "EMERGENCY"; | ||
| case SOLIDSYSLOG_SEVERITY_ALERT: | ||
| return "ALERT"; | ||
| case SOLIDSYSLOG_SEVERITY_CRITICAL: | ||
| return "CRITICAL"; | ||
| case SOLIDSYSLOG_SEVERITY_ERROR: | ||
| return "ERROR"; | ||
| case SOLIDSYSLOG_SEVERITY_WARNING: | ||
| return "WARNING"; | ||
| case SOLIDSYSLOG_SEVERITY_NOTICE: | ||
| return "NOTICE"; | ||
| case SOLIDSYSLOG_SEVERITY_INFORMATIONAL: | ||
| return "INFO"; | ||
| case SOLIDSYSLOG_SEVERITY_DEBUG: | ||
| return "DEBUG"; | ||
| } | ||
| return "?"; | ||
| } | ||
|
|
||
| /* The four a misconfigured integration raises. Role-specific categories sit in | ||
| * ranges above 0x0100 and print numerically. */ | ||
| static const char* CategoryName(uint16_t category) | ||
| { | ||
| switch (category) | ||
| { | ||
| case SOLIDSYSLOG_CAT_BAD_CONFIG: | ||
| return "bad-config"; | ||
| case SOLIDSYSLOG_CAT_BAD_ARGUMENT: | ||
| return "bad-argument"; | ||
| case SOLIDSYSLOG_CAT_POOL_EXHAUSTED: | ||
| return "pool-exhausted"; | ||
| case SOLIDSYSLOG_CAT_UNKNOWN_DESTROY: | ||
| return "unknown-destroy"; | ||
| default: | ||
| return NULL; | ||
| } | ||
| } | ||
|
|
||
| static void OnSyslogError(void* context, const struct SolidSyslogErrorEvent* event) | ||
| { | ||
| (void) context; | ||
|
|
||
| if (event == NULL) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| /* Sources are matched by pointer identity — Name is only ever a label, which | ||
| * is all it is used for here. */ | ||
| const char* source = ((event->Source != NULL) && (event->Source->Name != NULL)) ? event->Source->Name : "?"; | ||
| const char* category = CategoryName(event->Category); | ||
|
|
||
| if (category != NULL) | ||
| { | ||
| (void) printf("[syslog] %s %s %s (detail %ld)\n", SeverityName(event->Severity), source, category, (long) event->Detail); | ||
| } | ||
| else | ||
| { | ||
| (void) printf( | ||
| "[syslog] %s %s category 0x%04X (detail %ld)\n", | ||
| SeverityName(event->Severity), | ||
| source, | ||
| (unsigned int) event->Category, | ||
| (long) event->Detail | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| void SyslogErrorHandler_Install(void) | ||
| { | ||
| SolidSyslog_SetErrorHandler(OnSyslogError, NULL); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* The device's reaction to a SolidSyslog internal fault. | ||
| * | ||
| * Nothing in the library fails loudly — a _Create that cannot succeed returns a | ||
| * Null object instead — so a logger that has silently stopped looks exactly like | ||
| * one with nothing to say. This is the only thing that tells them apart, which | ||
| * is why it goes in before the first _Create and not after something looks | ||
| * wrong. */ | ||
| #ifndef SYSLOG_ERROR_HANDLER_H | ||
| #define SYSLOG_ERROR_HANDLER_H | ||
|
|
||
| /** Install the handler on the library's single global slot. Call once, at | ||
| * startup, before any SolidSyslog object is created. */ | ||
| void SyslogErrorHandler_Install(void); | ||
|
|
||
| #endif /* SYSLOG_ERROR_HANDLER_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # error-handler figures (bytes) — captured by scripts/run.sh (CAPTURE=1). | ||
| # The device reads measurements/Baseline.csv as its frozen baseline and reports current-minus-Baseline. | ||
| flash_text,350392 | ||
| flash_data,320 | ||
| static_bss,110880 | ||
| heap_used,4440 | ||
| mbedtls_peak,21336 | ||
| mbedtls_free,11432 | ||
| lwip_mem_free,7576 | ||
| lwip_pbufs_free,14 | ||
| stack_log,120 | ||
| stack_service,52 | ||
| stack_harness,2840 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.