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

Fix: Aggregate Logs and formatting #331

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

mkellerman
Copy link

@mkellerman mkellerman commented Jun 23, 2024

This is my first attempt at swift language. Any criticism welcome!

The formating of javascript console log is not formatted in a way that it is easy for others to read, or created automation around in parsing it. I suggestion here is to us as minimal code as possible to format the logs without it being a word to word regex replacement.

This can be tweaked and tailored, and some 'fixed' values could be addressed in a seperate method, but this is my first implementation.

This should also reduce the size of the log file considerably.

Let me know what you think!

@mkellerman
Copy link
Author

Previous Logs:

OpenAPS.swift - determineBasal(currentTemp:clock:) - 21 DEV: Start determineBasal
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: Middleware reason: Nothing changed
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: Pumphistory is empty!
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: insulinFactor set to : 55
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: Using weighted TDD average: 1 U, instead of past 24 h (0 U), weight: 0.65
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: , Dynamic ratios log: Dynamic Settings disabled
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: Default Half Basal Target used: 8.9 mmol/L
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: Autosens ratio: 1;
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: Threshold set to 3.9
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: ISF unchanged: 3
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: CR:10
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: currenttemp:0 lastTempAge:28652688m, tempModulus:18m
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: SMB disabled (no enableSMB preferences active or no condition satisfied)
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: profile.sens:3, sens:3, CSF:5.4
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: Carb Impact:-4.3mg/dL per 5m; CI Duration:0hours; remaining CI (1.5h peak):0mg/dL per 5m
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: UAM Impact:-4.3mg/dL per 5m; UAM Duration:0hours
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: minPredBG: 93 minIOBPredBG: 93 minZTGuardBG: 117
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log:  avgPredBG:117 COB/Carbs:0/0
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: BG projected to remain above 5.5 for 35minutes
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: BG projected to remain above 3.9 for 240minutes
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: naive_eventualBG:,117,bgUndershoot:,-47.5,zeroTempDuration:,240,zeroTempEffect:,216,carbsReq:,-49
JavaScriptWorker.swift - createContext() - 61 DEV: JavaScript log: Setting neutral temp basal of 1U/hr

New Logs:

JavaScriptWorker.swift - aggregateLogs() - 114 DEV: JavaScript log [JSON]: 
{
    "MiddlewareReason": "Nothing changed", 
    "Pumphistory": "empty", 
    "InsulinFactor": "55", 
    "WeightedTDDAverage": "1 U", "WeightedTDDAveragePast24h": "0 U", "Weight": "0.65", 
    "DynamicRatiosLog": "Dynamic Settings disabled", 
    "DefaultHalfBasalTarget": "8.9 mmol/L", 
    "AutosensRatio": "1", 
    "Threshold": "3.9", 
    "ISFUnchanged": "3", 
    "CR": "10", 
    "Currenttemp": "0", "LastTempAge": "28652688m", "TempModulus": "18m", 
    "SMBDisabled": "no enableSMB preferences active or no condition satisfied", 
    "ProfileSens": "3", "Sens": "3", "CSF": "5.4", 
    "CarbImpact": "-4.3mg/dL per 5m", "CIDuration": "0hours", "RemainingCI15hPeak": "0mg/dL per 5m", 
    "UAMImpact": "-4.3mg/dL per 5m", "UAMDuration": "0hours", 
    "MinPredBG": "93", "MinIOBPredBG": "93", "MinZTGuardBG": "117", 
    "AvgPredBG": "117", "COBCarbs": "0/0", 
    "BGProjected": "remain above 5.5 for 35minutes", 
    "BGProjected": "remain above 3.9 for 240minutes", 
    "NaiveEventualBG": "117", "BgUndershoot": "-47.5", "ZeroTempDuration": "240", "ZeroTempEffect": "216", "CarbsReq": "-49", 
    "NeutralTempBasal": "1U/hr", 
}

@marionbarker
Copy link
Contributor

Summary

This patch builds and runs. Probably needs a bit more work.

testing summary:

Before and After patch, logs appended at the end of this message as zip files.

After the rebuild (and not before), see this error message in logs:

2024-06-23T09:12:27-0700 [OpenAPS] JavaScriptWorker.swift - createContext() - 23 - DEV: JavaScript log: Mismatched number of resumes(2) and suspends(1)!
2

with some extra lines associated with that (I think).

Quantity Before After Delta
parser works yes yes -
last timestamp 2024-06-23T09:11:26-0700 2024-06-23T11:10:58-0700 -
lines 240,427 281,042 40,615
characters 2,307,917 2,766,866 458,949
hrs 9.183 11.183 2.00
lines/hr 26k - 20k
char/hr 251k - 229k

Configuration

I applied the patch from this PR to the alpha branch (where a number of PR have been accumulating prior to being merged to dev), commit 3ec6176.

Testing

  • started with an SE running Trio alpha attached to an rPi DASH
  • did a deactivate and pair new with old code/log
  • save the log to trio-pr331-before folder.
  • rebuild

Let it run for a while

  • save to log to trio-pr331-after folder

Configure the python parsing program still works:

Success:

Run OmniLoopMessageParser on the 2 log files.

Note that parser breaks logs into individual pods segments when more than one pod is detected, thus the second pod in the log started just before rebuilding to Trio with patch. The output report for that pod is summarized below.

  • before:
  This pod status:
            Pod active time (hrs) :    0.0
     Insulin delivered by pod (u) :    3.10 (from last 0x1d)

  Report below is for all messages to date for this pod

            First message in log : 2024-06-23 09:09:36
            Last  message in log : 2024-06-23 09:11:01
  Total elapsed time in log (hrs) :    0.0
       Total Bolus Req in log (u) :    3.10
  • after
  This pod status:
            Pod active time (hrs) :    2.0
     Insulin delivered by pod (u) :    4.40 (from last 0x1d)

  Report below is for all messages to date for this pod

            First message in log : 2024-06-23 09:09:36
            Last  message in log : 2024-06-23 11:09:06
  Total elapsed time in log (hrs) :    2.0
       Total Bolus Req in log (u) :    4.40

Log files:

Log before the rebuld:
log-pr-331-before.txt.zip

Log after the rebuild:
log-pr-331-after.txt.zip

@mkellerman
Copy link
Author

@marionbarker , i've updated the PR. Can you please re-run your script please to validate?

@marionbarker
Copy link
Contributor

Summary

  • First test successful - looks like logs are ~25% smaller
  • Files look cleaner, but I'm not an expert
  • Set up a test site to start uploading to Nightscout
    • looks right (I see treatments and forecasts)
    • will review in the morning

Details:

  • Built with Trio-dev, commit a364b62 plus this patch
  • Attach an rPi DASH simulator to the phone

Using the new logger:

  • check if pod message parser works and it does
  • Allow it to run just over 3 hours
  • Use the lines and characters per hour from first 16.83 hours of the day and compare with the log after the rebuild
Quantity Before This Test
parser works yes yes
hrs 16.83 3.38
lines 55,048 8,941
characters 4,795,192 685,890
lines/hr 3.3k 2.6k
char/hr 288k 203k

@mountrcg
Copy link
Contributor

mountrcg commented Jul 3, 2024

@mkellerman I like the shortening of the js-logging very much.

Could you elaborate which benefit you try to reap by converting the console.errors from js into something like "variable": "some statement"? For me it destroys some readability of the js debugging done by the console.error, e.g.

    "NaiveEventualBG": "106", "BgUndershoot": "-35", "ZeroTempDuration": "240", "ZeroTempEffect": "198", "CarbsReq": "-47", 
    "SMBNotLimitedByMaxIOBInsulinReq": "0.5 U)", 
    "EvBolusWouldNotBeLimitedByMaxIOBInsulinForManualBolus": "0.54 U).", 

But I also have to admit that autoISF has a lot more debugging implemented in a prosa like style, that you are not aware of:

 "unknown": "----------------------------------", 
    "unknown": "start autoISF", 
    "unknown": "----------------------------------", 
    "B30Enabled": "true", 
    "unknown": "B30 last bolus above limit of 1.5U was 0U", "unknown": " 1m ago", 
    "B30Activation": "false", 
    "B30TTset": "false", "unknown": " at 101", "unknown": " last Bolus of 0U", "1mAgoITimeRemaining": "-1m.", 
    "SMBDisabledProfileTarget101": "odd number", 
    "unknown": "Loop at minimum power", 
    "unknown": "loop_smb function overriden with autoISF checks", "unknown": " enableSMB = false", 
    "Glucose": "108", "Noise": "0", "Delta": "4", "ShortAvgdelta": "3.67", "LongAvgdelta": "2.35", "CgmFlatMinutes": "0", "Date": "1719987002000", "DuraISFMinutes": "5", 
    ```

    which becomes quite unreadable. But that also applies to some standard oref output as the first citred lines show.

@mkellerman
Copy link
Author

@mountrcg thanks for testing out my PR!

I haven’t tested all possible outputs from these JavaScripts, and some will only output based on specific settings.

Can you send me your log file from a previous run? Not one from my execution?

I’ll attempt to add the fixes for those outputs as well.

But if you have the courage, attempt some regex magic and push up a code suggestion! 😂

@dnzxy
Copy link
Contributor

dnzxy commented Jul 3, 2024

Can you send me your log file from a previous run? Not one from my execution?

I’ll attempt to add the fixes for those outputs as well.

Robert‘s logs stem from a fork of Trio that runs an altered algorithm, thus does not need to be supported by a potential Trio log parser; if wanted or required that will have to be extended within that fork.

@dnzxy
Copy link
Contributor

dnzxy commented Jul 3, 2024

Could you provide a full log.txt (maybe let it run for 2-3 loop cycles) with the newly added and changed parser to compare changes made?

@marionbarker
Copy link
Contributor

I reversed the patch and rebuilt at 06:45 local.

The plan is to save logs and split into with and without patch segments of 15 minutes each.

@mkellerman
Copy link
Author

Once all possible outputs have been evaluated from the JS output, it will be great, but in the mean time, do we want the original unprocessed logs to come out into the logs?

i have the choice between JSON, INVALID_JSON (which is what you’re seeing now), RAW.

@marionbarker
Copy link
Contributor

Log Samples

Forgot to restart the rPi DASH simulator after rebuidling.
Resumed the "pump" at 06:54:08 - so use that timestamp, in addition, to help split the log file into pieces.

Graphic shows with patch on left and straight dev on the right. (Picked a section with Middleware).

log-compare

Log with patch (15 minute chunk):

Log with no patch (15 minute chunk):

Full log in case it is desired:

Timing details and selection of log snippets:

Decide to define a "cycle" as the line with [DeviceManager] FetchGlucoseManager.swift with 217 - DEV: New glucose found

grep "217 - DEV: New glucose found" log.txt

for clarity, do a s/r to remove repeated text below:

2024-07-03T00:00:55-0700  - 217 - DEV: New glucose found
2024-07-03T00:04:10-0700  - 217 - DEV: New glucose found
. . .
2024-07-03T06:30:31-0700  - 217 - DEV: New glucose found << first line for log with patch (line 14927)
2024-07-03T06:35:31-0700  - 217 - DEV: New glucose found
2024-07-03T06:40:31-0700  - 217 - DEV: New glucose found
2024-07-03T06:44:43-0700  - 217 - DEV: New glucose found << end, line before here (line 15523) delta 596
** rebuild here
2024-07-03T06:50:37-0700  - 217 - DEV: New glucose found
** resume pump here
2024-07-03T06:55:37-0700  - 217 - DEV: New glucose found
2024-07-03T07:00:37-0700  - 217 - DEV: New glucose found << first line for log, straight dev (line 16824)
2024-07-03T07:05:37-0700  - 217 - DEV: New glucose found
2024-07-03T07:10:37-0700  - 217 - DEV: New glucose found
2024-07-03T07:15:37-0700  - 217 - DEV: New glucose found << end, line before here (line 17587) delta 763
2024-07-03T07:20:37-0700  - 217 - DEV: New glucose found

@mountrcg
Copy link
Contributor

mountrcg commented Jul 4, 2024

Robert‘s logs stem from a fork of Trio that runs an altered algorithm, thus does not need to be supported by a potential Trio log parser; if wanted or required that will have to be extended within that fork.

The upper part is standard logging.

"NaiveEventualBG": "106", "BgUndershoot": "-35", "ZeroTempDuration": "240", "ZeroTempEffect": "198", "CarbsReq": "-47", 
"SMBNotLimitedByMaxIOBInsulinReq": "0.5 U)", 
"EvBolusWouldNotBeLimitedByMaxIOBInsulinForManualBolus": "0.54 U).", 

Readability of the java-logs is a tuned down by omitting spaces in prosa and forcing everything into a "variable": "value", scheme.

@dnzxy
Copy link
Contributor

dnzxy commented Jul 4, 2024

Readability of the java-logs is a tuned down by omitting spaces in prosa and forcing everything into a "variable": "value", scheme.

Yes, that’s what Marc is proposing here to cut the log size down drastically. I guess it’s a subjective thing if this is tuned down or improved. I was referring to the lines of "unknown" : "some value".

I also brought this up on Discord, where I pointed out that specific entries need to be logged after one another and that there’s a certain "order" of the logging and that needs to be kept so that the log stays readable.

@mountrcg
Copy link
Contributor

mountrcg commented Jul 4, 2024

I did not find your comment in discord @dnzxy . I totally think the idea of reducing the the size of the logs is great. An a lot is achieved to delete the trillion chars befor the actual content of the logging.
But changing the content of the oref logging and pressing it in a certain scheme does not serve a meaningful purpose of reducing log size. The few spaces that are omitted do not really count, and lots of "" are added. If we want to change the content of the oref logging we can do that in oref, why do it later under the pretense of reducing size?
Whoever did the oref logging does it for a purpose.m Fixing the size is something that concerns how iAPS/Trio handled the individual log entries and adding information, so this PR should focus on that part and not the content originating in oref. We have all flexibility to change it directly in oref.

@scottleibrand
Copy link
Member

I have no experience with or opinion on these changes, but some historical context: the oref0 logs were optimized for tailing a log file in real time on a Linux console. The phone use case is quite different, so I wouldn’t be surprised if the optimal logging format is also.

@dnzxy
Copy link
Contributor

dnzxy commented Jul 4, 2024

@mountrcg It's probably somewhere buried deep down in the beta-testing channel, maybe even in a thread 😂 I don't have it handy right now, sorry.

An a lot is achieved to delete the trillion chars befor the actual content of the logging.

I'm not sure what you mean by this. If it's the hundreds of -, x, + log entries, yes that is the Autosens output and that should definitely also be aggregated. I'm mentioned this previously in #272 .

Whoever did the oref logging does it for a purpose.m Fixing the size is something that concerns how iAPS/Trio handled the individual log entries and adding information, so this PR should focus on that part and not the content originating in oref. We have all flexibility to change it directly in oref.

I'm with you in principle, the logs need to be readable and comprehensible, you need to still be able to follow the "oref workflow" from the logs. It does serve a purpose to press it in a "certain scheme". What Marc has proposed here takes the output every loop run prints into the log file from high double digit log entries (lets go with 25 for ease for argument) into 1 single long entry. He is flushing and aggregating the logs. That is meaningful, and a common best practice.

What we need to work out, and I'm sure Marc is happy to work on constructive input and ideas, is how to get the best of both worlds: a) aggregated logs, while b) keeping the oref "logging order" intact.

@scottleibrand thanks for providing some historical context. I guess tailing here means "following along on stdout", not so much using tail, right? Or were you guys tailing a certain number of lines and then just reading along? Can you also share some insight why most of the logs are console.error() and not .log()?

@mountrcg
Copy link
Contributor

mountrcg commented Jul 4, 2024

I'm not sure what you mean by this. If it's the hundreds of -, x, + log entries, yes that is the Autosens output and that should definitely also be aggregated. I'm mentioned this previously in #272 .

Yes I meant the condesing like Marion showed nicely in her comparison screen:

screen_logging

I am just not happy with changing the content of the logging, like in the purple magnification glas. What purpose does that serve?

@mkellerman
Copy link
Author

Thank you for everyones feedback! Love the discussion.

We have a bit of a conflict here. There are 2 issues that is being addressed:

  • Log formatting
  • Log size

Regarding size, it's clearly doing its job.

Regarding formatting, i think most of the confusion is derived by the output when a log line is not in a key/value pair, and i put it under 'unknown'. I had it this way so i can clearly see what i need to fix my regex for.

I will be attempting to correct that today, so please expect a change and re-evaluate the output.

@mountrcg
Copy link
Contributor

mountrcg commented Jul 4, 2024

I found the discussion in discord, sry that I did not see before. What would be the reason for trying to find the somewhat elegant solution (I like the sound of that!)?

Okay, i found a somewhat elegant solution. Will commit my changes. If someone wants to take a peak?
MKellerman (PST) — 06/23/2024 5:52 PM

JavaScriptWorker.swift - aggregateLogs() - 111 DEV: JavaScript log [JSON]: 
{
    "MiddlewareReason": "Nothing changed", 
    "Pumphistory": "empty", 
    "InsulinFactor": "55", 
    "WeightedTDDAverage": "1 U", "WeightedTDDAveragePast24h": "0 U", "Weight": "0.65", 
    "DynamicRatiosLog": "Dynamic Settings disabled", 
    "DefaultHalfBasalTarget": "8.9 mmol/L", 
    "AutosensRatio": "1", 
    "Threshold": "3.9", 
    "ISFUnchanged": "3", 
    "CR": "10", 
    "Currenttemp": "0", "LastTempAge": "28652632m", "TempModulus": "22m", 
    "SMBDisabled": "no enableSMB preferences active or no condition satisfied", 
    "ProfileSens": "3", "Sens": "3", "CSF": "5.4", 
    "CarbImpact": "3.6mg/dL per 5m", "CIDuration": "0hours", "RemainingCI15hPeak": "0mg/dL per 5m", 
    "UAMImpact": "3.6mg/dL per 5m", "UAMDuration": "0.7hours", 
    "MinPredBG": "149", "MinIOBPredBG": "149", "MinZTGuardBG": "129", 
    "AvgPredBG": "149", "COBCarbs": "0/0", 
    "BGProjected": "remain above 5.5 for 240minutes", 
    "NaiveEventualBG": "129", "BgUndershoot": "-59.5", "ZeroTempDuration": "240", "ZeroTempEffect": "216", "CarbsReq": "-51", 
    "InsulinReq": "0.93 U", 
    "InsulinForManualBolus": "0.94 U", 
    "NeutralTempBasal": "1U/hr", 
}

Is to put it in some log analysis that expects key-value pairs?

The logging in oref does not just come from determine-basal.js but also from the tempbasal functions und glucose-get-last modules and contains many textual/explanation strings. I pushed a couple PR's to oref0 repo to clean up some of that logging. I guess that can still be done, in contrast to:

MKellerman (PST) — 06/21/2024 5:04 AM
Okay, so doing a regex on the logs is a shit show. What are the chances we can modify the original js scripts?
Sjoerd BO3 (CET) — 06/21/2024 7:48 AM
zero to none 🙂

@mkellerman
Copy link
Author

I realize that this might be ambitious, and there are many log outputs that needs to be cleaned up. I was told that we shouldn't be touching the original js scripts, so doing my best to do it post processing.

@mkellerman
Copy link
Author

autosense()

OpenAPS.swift - autosense() - 305 DEV: Start autosens
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: Using most recent,104,deviations since,Wed Jul 03 2024 07:52:53 GMT-0700 (Pacific Daylight Saving Time)
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: 29% of non-meal deviations positive (>50% = resistance)
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: 52% of non-meal deviations negative (>50% = sensitivity)
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: RMS deviation: 5.21
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: Insulin sensitivity detected:
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: ISF adjusted from 54 to 69
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: Using most recent,288,deviations since,Wed Jul 03 2024 07:52:53 GMT-0700 (Pacific Daylight Saving Time)
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: 37% of non-meal deviations positive (>50% = resistance)
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: 52% of non-meal deviations negative (>50% = sensitivity)
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: RMS deviation: 7.79
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: Insulin sensitivity detected:
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: ISF adjusted from 54 to 69
OpenAPS.swift - autosense() - 321 DEV: AUTOSENS: {
    "ratio": 0.78,
    "newisf": 69
}

@mkellerman
Copy link
Author

determineBasal()

OpenAPS.swift - determineBasal(currentTemp:clock:) - 21 DEV: Start determineBasal
JavaScriptWorker.swift - aggregateLogs() - 122 DEV: JavaScript log: {
    "MiddlewareReason": "Nothing changed",
    "Pumphistory": "empty",
    "InsulinFactor": "55",
    "WeightedTDDAverage": "1 U", "WeightedTDDAveragePast24h": "0 U", "Weight": "0.65",
    "DynamicRatiosLog": "Dynamic Settings disabled",
    "DefaultHalfBasalTarget": "8.9 mmol/L",
    "AutosensRatio": "0.78",
    "Threshold": "3.9",
    "ISFFrom3": "3.8",
    "CR": "10",
    "Currenttemp": "0", "LastTempAge": "28668413m", "TempModulus": "23m",
    "ProfileSens": "3", "Sens": "3.8", "CSF": "6.9",
    "CarbImpact": "2.8mg/dL per 5m", "CIDuration": "0hours", "RemainingCI1923076923076923hPeak": "0mg/dL per 5m",
    "UAMImpact": "2.8mg/dL per 5m", "UAMDuration": "0.9hours",
    "MinPredBG": "165", "MinIOBPredBG": "165", "MinZTGuardBG": "150",
    "AvgPredBG": "165", "COBCarbs": "0/0",
    "BGProjected": "remain above 5.5 for 240minutes",
    "NaiveEventualBG": "150", "BgUndershoot": "-80.5", "ZeroTempDuration": "240", "ZeroTempEffect": "277", "CarbsReq": "-52",
    "InsulinReq": "0.95 U",
    "InsulinForManualBolus": "0.98 U",
}
JavaScriptWorker.swift - aggregateLogs() - 132 DEV: JavaScript log: SMB disabled (no enableSMB preferences active or no condition satisfied)
OpenAPS.swift - determineBasal(currentTemp:clock:) - 80 DEV: SUGGESTED: {
    "temp": "absolute",
    "bg": 150,
...

@mkellerman
Copy link
Author

As you can see with the SMB disabled (no enableSMB preferences active or no condition satisfied), instead of being under unknown, it's now going to output as a single line entry, but keep the rest of the valid JSON format for the rest of the log.

What do people think of this?

@dnzxy
Copy link
Contributor

dnzxy commented Jul 4, 2024

Love it. The autosens parsing alone will save another double-digits percentage in log size.

Is to put it in some log analysis that expects key-value pairs?
[…]
...and contains many textual/explanation strings.

Yes. Logs usually aren't written in prosa. This makes for a way cleaner log and instead of looking for explanation strings we can start looking for specific keywords. If you are after explanation, a glossary can be added to some docs for example, to give you keyword-explanation.

@mkellerman
Copy link
Author

mkellerman commented Jul 4, 2024

Also, maybe i'm doing this all wrong, and we should just have a DEBUG=true flag in the settings, and if so, we get the raw output from the JS execution. when DEBUG=false, we could add the actual data that is a result of the execution... for example:

OpenAPS.swift - oref2() - 296 DEV: Oref2_variables(average_total_data: 0, weightedAverage: 1, past2hoursAverage: 0, date: 2024-07-04 15:57:18 +0000, isEnabled: false, presetActive: false, overridePercentage: 100, useOverride: false, duration: 0, unlimited: true, hbt: 160, overrideTarget: 0, smbIsOff: false, advancedSettings: false, isfAndCr: false, isf: false, cr: false, smbIsScheduledOff: false, start: 0, end: 0, smbMinutes: 30, uamMinutes: 30)

@dnzxy
Copy link
Contributor

dnzxy commented Jul 4, 2024

I like the idea (a bit like ssh-ing into a container and seeing what’s off 😂) but the thing with AID apps is that you want to log as much as you can in case of a sudden issue / crash / fatal error, so you can at least know what went on after the fact.

Imagine you suddenly got insulin, you are not sure why, you tend to the FB groups or FB, you describe the situation. If volunteers can’t immediately explain it to you, a good hard look at the logs will always tell people what went on (more often than not user error or unintended things by inputs of an uneducated user), and that is really important.

I could totally see something like a more verbose dev outputs that’s even more detailed, but the degree verbosity should probably be kept yet the output cleaned up a bit.

@mkellerman
Copy link
Author

In the event of a crash, i think my implementation might cause issues. It's groupping the output, and processing it, before writing to disk. So if there is any failures during the execution of the JS, then it wont be logged to file.

Might be best to consider modifying the original JS files? :|

@dnzxy
Copy link
Contributor

dnzxy commented Jul 4, 2024

It will be written to the log file every single loop and every time the algorithm runs, to be more precise when the specific worker is called, so that’s alright; unless I am interpreting things wrong here. I meant that we will at least have output every 5 min loop. If you have to enable debug logging that will be a hard thing to do 😊

@scottleibrand
Copy link
Member

@scottleibrand thanks for providing some historical context. I guess tailing here means "following along on stdout", not so much using tail, right? Or were you guys tailing a certain number of lines and then just reading along? Can you also share some insight why most of the logs are console.error() and not .log()?

Tail the logs means something like tail -f pump-loop.log. So yes, real time. The console.error was a node.js workaround IIRC.

@dnzxy
Copy link
Contributor

dnzxy commented Jul 4, 2024

Tail the logs means something like tail -f pump-loop.log. So yes, real time. The console.error was a node.js workaround IIRC.

Okay so tailing number of lines, makes sense to make it more prosa read-along like then 👍 thanks again for the insight.

Would you accept PRs to the oref repository to change that? Are there still users of the rPi rigs that require these workaround? Could this be changed?

@scottleibrand
Copy link
Member

There were some alternative logging formats implemented, which wrote to different log files. You could probably adapt that. I still tail -f pump-loop.log on our rigs.

@mkellerman
Copy link
Author

So, what do we want to do with this PR?

@dnzxy
Copy link
Contributor

dnzxy commented Jul 5, 2024

So, what do we want to do with this PR?

I'd consider this PR to be an improvement as long as we keep with the "order" of oref log statements.

There is a long-term goal of no longer using JavaScript sources but to utilizing the AAPS Kotlin-based oref-rewrite (some time down the road, lol), so I don't think changing JS sources is a win. This is a good compromise and hits the middle ground.

Also, with a major rewrite of the persistence layer to core data, logging will inherently [need to] change anyways, so I think an overall look at "how can we improve logging" will be necessary then anyways. Maybe you'd be up to also chime in there and support that effort 🚀

I'm but one opinion here though, lets see what others think 🤔 Thank you for your work here and putting this up as a proposal 👏

@mkellerman
Copy link
Author

I’m going to split up this PR. There are 2 items:

  • Removal of empty lines and cleanup of Autosens logs, which will reduce the log size considerably.
  • Try and cleanup the rest of the logs can be done one PR at a time, so it can be tested and tested separately.

I’ll tag the PR once I’m done, but let’s not close this PR for now so others can chime in if they want.

@dnzxy
Copy link
Contributor

dnzxy commented Jul 18, 2024

I'll convert this into a draft so it still stays open and visible here in the repository, but isn't considered as "we need to look at this, review it, get it merged" type TODO.

@dnzxy dnzxy marked this pull request as draft July 18, 2024 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants