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

Advanced File Output #65

Merged
merged 16 commits into from
Mar 23, 2024
Merged

Advanced File Output #65

merged 16 commits into from
Mar 23, 2024

Conversation

pyciko
Copy link

@pyciko pyciko commented Mar 6, 2024

This type of file output is mainly targeted for low-cost IoT platforms (like RPi). It optimises some of the aspects of the original File Output, specifically:

  • It has an internal temporary buffer which accumulates the logs and prints them out after a certain period. This reduces the frequency of file writes which is good for microSD storages and other types of cheap storages on IoT devices. It is possible to specify the levels of messages which are printed out immediately, without waiting for the next timer tick. By default these are warnings, errors and fatals.
  • It has a simple manager for dynamically creating log files instead of using a single one specified by the user. The log files are created in two scenarios: on logger init and when the current log file reaches a size limit. The file names consists of a date+time followed by either "-init" or "-next" suffix depending on the reason why the file was created. This is useful for writing "archives" of telemetry data and logs while keeping them structured.

pyciko added 4 commits March 6, 2024 11:49
- Temporary buffer to reduce writes frequency
- Dynamic log files creation inside a specified directory
Updated naming format to have a fixed len and use _ instead of space to avoid forgetting quotes in console commands like "cat ~/logs/...."
@Bungeefan
Copy link
Member

Hi! Thanks for the nice pull request!

However, before further reviewing your request, unfortunately, the check for Dart 2.17 failed.
Platform.lineTerminator was only introduced in Dart 3.1.0 and this library tries to maintain compatibility with at least 2.17.

I would suggest that you simply replace your usages with the original implementation behind the property:

static String get lineTerminator => isWindows ? '\r\n' : '\n';

https://github.com/dart-lang/sdk/blob/3.1.0/sdk/lib/io/platform.dart#L245

@pyciko
Copy link
Author

pyciko commented Mar 8, 2024

Done

Copy link
Member

@Bungeefan Bungeefan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the nice pull request, please check my comments and feel free to ask if you need more clarification!

lib/src/outputs/advanced_file_output.dart Outdated Show resolved Hide resolved
lib/src/outputs/advanced_file_output.dart Outdated Show resolved Hide resolved
lib/src/outputs/advanced_file_output.dart Show resolved Hide resolved
lib/src/outputs/advanced_file_output.dart Outdated Show resolved Hide resolved
lib/src/outputs/advanced_file_output.dart Outdated Show resolved Hide resolved
lib/src/outputs/advanced_file_output.dart Show resolved Hide resolved
lib/src/outputs/advanced_file_output.dart Outdated Show resolved Hide resolved
lib/src/outputs/advanced_file_output.dart Outdated Show resolved Hide resolved
lib/src/outputs/advanced_file_output.dart Outdated Show resolved Hide resolved
lib/src/outputs/advanced_file_output_stub.dart Outdated Show resolved Hide resolved
@Bungeefan
Copy link
Member

That was quick, thanks!
I submitted a review (my first ever on GitHub), you should be able to see it now.
Don't be put off by the amount of comments, I still consider your pull request as well-made!

- General function for nums padding
- String path
- Detailed class explaination
- Non-null assertion operator in _openFile
pyciko and others added 4 commits March 11, 2024 13:18
- Made most of the fields private
- Added custom file format field
- Changed default naming logic to a more traditional one
- Fixed buffer flushing logic on destroy + added a test
- Added logging for exceptions on closing a file
- Simplified open and close file function calls
@Bungeefan
Copy link
Member

Feel free to overwrite my changes as you see fit.

@Bungeefan
Copy link
Member

Please review the new documentation, I tried to implement your description as well as I could!

@pyciko
Copy link
Author

pyciko commented Mar 12, 2024

Thanks, yeah, English is not my native lang, your text looks much better.

@pyciko
Copy link
Author

pyciko commented Mar 23, 2024

Thx for approval, can't wait to see it released!

@pyciko pyciko closed this Mar 23, 2024
@Bungeefan Bungeefan reopened this Mar 23, 2024
@Bungeefan Bungeefan merged commit 5363714 into SourceHorizon:main Mar 23, 2024
4 checks passed
@Bungeefan
Copy link
Member

Sure, maybe next time don't close it if you want it to be merged ;)

Anyway, thanks again for the nice FileOutput!
I think it's a fantastic addition to this project, and thank you for keeping up with my repeated change requests!

@Bungeefan
Copy link
Member

logger v2.2.0 is now available on pub.dev!

@neiljaywarner
Copy link

so sorry if this is a dumb question, but does this library include file logging or is it a possible future thing?

@pyciko
Copy link
Author

pyciko commented Apr 12, 2024

so sorry if this is a dumb question, but does this library include file logging or is it a possible future thing?

If you're using version 2.2.0 or newer, it does include Advanced File Logging with functions described above. It also includes basic FileLogger that existed even earlier.

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.

3 participants