Skip to content

fix(ffi): fixed create simple logger implementation, removed duplicated word in comment#95

Merged
atulkhare4096 merged 1 commit into
microsoft:mainfrom
aido-mth:aido/fix_ffi_test
Apr 23, 2026
Merged

fix(ffi): fixed create simple logger implementation, removed duplicated word in comment#95
atulkhare4096 merged 1 commit into
microsoft:mainfrom
aido-mth:aido/fix_ffi_test

Conversation

@aido-mth
Copy link
Copy Markdown
Contributor

Description

This PR resolves an initialization failure in the FFI tutorial example where create_simple_logger fails to create a logger if the target log file does not already exist.

Currently, the create_simple_logger function hardcodes the overwrite parameter to false when calling SimpleLogger::new. Under the hood, the create_or_open_log_file helper routes false to OpenOptions::new().write(true).append(true).open(log_file). Because it lacks the .create(true) flag, this call returns an error on a fresh run when the file is absent. As a result, the FFI wrapper catches the error, returns 1, and leaves the C-caller without a valid logger instance. From my perspective, current behavior is somewhat counterintuitive for an educational example, as it forces the reader to manually create the file before running the code or figure out why it silently fails.

Proposed Changes

To ensure the example works out-of-the-box:

  • Default Flag Adjustment: Changed the hardcoded overwrite argument from false to true inside create_simple_logger. This ensures File::create is called, guaranteeing the file is generated if it doesn't exist.
  • Comment Typo Fix: Removed a duplicated preposition (in in real life -> in real life) in the adjacent comment block.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation Update

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have tested the changes locally.

@atulkhare4096 atulkhare4096 merged commit b97167e into microsoft:main Apr 23, 2026
1 check passed
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.

2 participants