Skip to content

Improve readability by extracting separate types to their own files#444

Merged
kukushechkin merged 3 commits into
apple:mainfrom
samuelmurray:extract-types-to-separate-files
Apr 17, 2026
Merged

Improve readability by extracting separate types to their own files#444
kukushechkin merged 3 commits into
apple:mainfrom
samuelmurray:extract-types-to-separate-files

Conversation

@samuelmurray
Copy link
Copy Markdown
Contributor

Improve readability be extracting separate types to their own files

Motivation:

Logger.swift is >2000 LoC, which makes it hard to navigate both for contributors and users of swift-log. Widely different concepts, such as concrete LogHandler implementations, are mixed with core types such as Logger.Level. Extracting separate types should make it easier to find what you are looking for.
Closes #441

Modifications:

  • Extract all (not Logger-namespaced) types from Logging.swift to separate files.
  • Rename Logging.swift to Logger.swift, as this is the only remaining top-level type.
  • Change LoggingSystem.factory from fileprivate to internal to be accessible from Logger.swift.

Result:

Each (non-private) top-level type lives in a separate file, named after the type.

@samuelmurray
Copy link
Copy Markdown
Contributor Author

We still have ~1000 LoC in Logger.swift of various log methods. To me, it would make sense to move all except the base Logger.log(...) and the internal Logger._log() to a separate file.

@kukushechkin kukushechkin added the 🔨 semver/patch No public API change. label Apr 16, 2026
@kukushechkin
Copy link
Copy Markdown
Contributor

Thanks for tackling this, @samuelmurray!

The license headers check is failing because StdioOutputStream.swift uses an Xcode-generated file header instead of the project's standard license header.

But another thing that bothers me for some reason is StdioOutputStream.swift being in the package root, but used by the handler in Handlers folder. I would suggest moving struct StdioOutputStream into the corresponding handler.

@samuelmurray samuelmurray changed the title Improve readability be extracting separate types to their own files Improve readability by extracting separate types to their own files Apr 16, 2026
@samuelmurray
Copy link
Copy Markdown
Contributor Author

But another thing that bothers me for some reason is StdioOutputStream.swift being in the package root, but used by the handler in Handlers folder. I would suggest moving struct StdioOutputStream into the corresponding handler.

Yeah, you're right. I was a bit unsure where to put it, as it was referenced from LoggingTest.swift, but actually that just points to the tests could benefit from having the same separation. I'll move tests that clearly belong to a specific handler to corresponding test files.

…files

Move StdioOutputStream to same file as StreamLogHandler, and extract related tests to separate file
@samuelmurray
Copy link
Copy Markdown
Contributor Author

samuelmurray commented Apr 16, 2026

@kukushechkin I had a typo in my commit message ("be" -> "by") - I'm not sure what ends up in the final commit message when you merge, but I didn't want to ammend/rebase during active review. Can you fix it when merging?

@kukushechkin kukushechkin enabled auto-merge (squash) April 17, 2026 09:49
@kukushechkin kukushechkin merged commit 25598b6 into apple:main Apr 17, 2026
57 checks passed
@kukushechkin
Copy link
Copy Markdown
Contributor

Thank you @samuelmurray for this improvement! I've fixed "be" -> "by" in the merge commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve code readability by splitting large source files

2 participants