Skip to content

Improvements to logging in the app using swift-log and structured logging #168

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

Conversation

xtremekforever
Copy link
Contributor

This is a draft since I've only done the initial set of changes. The output currently looks like this with the logger being used almost everywhere, and with structured logging being used:

$ swift run swift-sdk-generator make-linux-sdk --swift-version 6.0.3-RELEASE --host x86_64-unknown-linux-gnu --target aarch64-unknown-linux-gnu
warning: 'swift-algorithms': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
    ~/swift-sdk-generator/.build/checkouts/swift-algorithms/Sources/Algorithms/Documentation.docc
Building for debugging...
[79/79] Linking swift-sdk-generator
Build of product 'swift-sdk-generator' complete! (14.74s)
2025-01-17T10:19:19-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] 
Downloading required toolchain packages...
2025-01-17T10:19:21-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] Using downloaded artifacts in these locations:
2025-01-17T10:19:21-0500 info org.swift.swift-sdk-generator : path=~/swift-sdk-generator/Artifacts/target_swift_6.0.3-RELEASE_aarch64-unknown-linux-gnu.tar.gz [SwiftSDKGenerator] -
2025-01-17T10:19:21-0500 info org.swift.swift-sdk-generator : path=~/swift-sdk-generator/Artifacts/host_swift_6.0.3-RELEASE_x86_64-unknown-linux-gnu.tar.gz [SwiftSDKGenerator] -
2025-01-17T10:19:21-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] 
Parsing Ubuntu packages list...
2025-01-17T10:19:23-0500 info org.swift.swift-sdk-generator : packageCount=11 [SwiftSDKGenerator] Downloading Ubuntu packages...
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : size=40 KB url=http://ports.ubuntu.com/ubuntu-ports/pool/main/g/gcc-12/libgcc-s1_12.3.0-1ubuntu1~22.04_arm64.deb [SwiftSDKGenerator] Downloaded
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : size=57 KB url=http://ports.ubuntu.com/ubuntu-ports/pool/main/z/zlib/zlib1g_1.2.11.dfsg-2ubuntu9.2_arm64.deb [SwiftSDKGenerator] Downloaded
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : size=1.5 MB url=http://ports.ubuntu.com/ubuntu-ports/pool/main/g/glibc/libc6-dev_2.35-0ubuntu3.8_arm64.deb [SwiftSDKGenerator] Downloaded
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : size=163 KB url=http://ports.ubuntu.com/ubuntu-ports/pool/main/z/zlib/zlib1g-dev_1.2.11.dfsg-2ubuntu9.2_arm64.deb [SwiftSDKGenerator] Downloaded
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : size=2.7 MB url=http://ports.ubuntu.com/ubuntu-ports/pool/main/g/glibc/libc6_2.35-0ubuntu3.8_arm64.deb [SwiftSDKGenerator] Downloaded
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : size=661 KB url=http://ports.ubuntu.com/ubuntu-ports/pool/main/g/gcc-12/libstdc++6_12.3.0-1ubuntu1~22.04_arm64.deb [SwiftSDKGenerator] Downloaded
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : size=1.2 MB url=http://ports.ubuntu.com/ubuntu-ports/pool/main/g/gcc-12/libgcc-12-dev_12.3.0-1ubuntu1~22.04_arm64.deb [SwiftSDKGenerator] Downloaded
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : size=1.3 MB url=http://ports.ubuntu.com/ubuntu-ports/pool/main/l/linux/linux-libc-dev_5.15.0-130.140_arm64.deb [SwiftSDKGenerator] Downloaded
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : size=11.6 MB url=http://ports.ubuntu.com/ubuntu-ports/pool/main/i/icu/libicu-dev_70.1-2_arm64.deb [SwiftSDKGenerator] Downloaded
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : size=2.2 MB url=http://ports.ubuntu.com/ubuntu-ports/pool/universe/g/gcc-12/libstdc++-12-dev_12.3.0-1ubuntu1~22.04_arm64.deb [SwiftSDKGenerator] Downloaded
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : size=10.5 MB url=http://ports.ubuntu.com/ubuntu-ports/pool/main/i/icu/libicu70_70.1-2_arm64.deb [SwiftSDKGenerator] Downloaded
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : fileName=libc6_2.35-0ubuntu3.8_arm64.deb [SwiftSDKGenerator] Extracting deb package...
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : fileName=libc6-dev_2.35-0ubuntu3.8_arm64.deb [SwiftSDKGenerator] Extracting deb package...
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : fileName=libgcc-s1_12.3.0-1ubuntu1~22.04_arm64.deb [SwiftSDKGenerator] Extracting deb package...
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : fileName=libgcc-12-dev_12.3.0-1ubuntu1~22.04_arm64.deb [SwiftSDKGenerator] Extracting deb package...
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : fileName=libicu70_70.1-2_arm64.deb [SwiftSDKGenerator] Extracting deb package...
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : fileName=libicu-dev_70.1-2_arm64.deb [SwiftSDKGenerator] Extracting deb package...
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : fileName=libstdc++-12-dev_12.3.0-1ubuntu1~22.04_arm64.deb [SwiftSDKGenerator] Extracting deb package...
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : fileName=libstdc++6_12.3.0-1ubuntu1~22.04_arm64.deb [SwiftSDKGenerator] Extracting deb package...
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : fileName=linux-libc-dev_5.15.0-130.140_arm64.deb [SwiftSDKGenerator] Extracting deb package...
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : fileName=zlib1g_1.2.11.dfsg-2ubuntu9.2_arm64.deb [SwiftSDKGenerator] Extracting deb package...
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : fileName=zlib1g-dev_1.2.11.dfsg-2ubuntu9.2_arm64.deb [SwiftSDKGenerator] Extracting deb package...
2025-01-17T10:19:25-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] 
Unpacking and copying Swift binaries for the host triple...
2025-01-17T10:19:37-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] 
Unpacking Swift distribution for the target triple...
2025-01-17T10:19:49-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] 
Copying Swift core libraries for the target triple into Swift SDK bundle...
2025-01-17T10:19:50-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] 
Fixing up absolute symlinks...
2025-01-17T10:19:51-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] 
Generating toolset JSON file...
2025-01-17T10:19:51-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] 
Generating destination JSON file...
2025-01-17T10:19:51-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] 
Generating .artifactbundle manifest file...
2025-01-17T10:19:51-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] 
All done! Install the newly generated SDK with this command:
swift experimental-sdk install ~/swift-sdk-generator/Bundles/6.0.3-RELEASE_ubuntu_jammy_aarch64.artifactbundle

After that, use the newly installed SDK when building with this command:
swift build --experimental-swift-sdk 6.0.3-RELEASE_ubuntu_jammy_aarch64
2025-01-17T10:19:51-0500 info org.swift.swift-sdk-generator : elapsedTime=31 seconds [GeneratorCLI] 
Generator run finished successfully.

So, questions:

  • For human readable output, ideally we'd remove the timestamp, label, and module name from the log output, right @euanh ?
  • Should we maybe look at switching the order of the metadata so that it appears after the log message? e.g. "Generator run finished successfully. elapsedTime=31 seconds" @MaxDesiatov

I haven't figured out how to change the logger output format, but I can have a look a bit later.

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Jan 17, 2025

I wonder if we should introduce a --verbose/-v flag that sets the log level to info or change the level for existing messages to something like debug? Or keep levels of individual messages as they are, but introduce a --quiet/-q flag that hides info messages from the output? In either case seems acceptable to keep the format as it is, unless we could form a consensus for making swift-log output as human readable as print output was? (I'm myself open to either possibility at this point)

@xtremekforever
Copy link
Contributor Author

Looks like there is already a --verbose flag:

The default `--target` triple is Linux with the same CPU architecture with host triple

USAGE: swift-sdk-generator make-linux-sdk <options>

OPTIONS:
  --bundle-version <bundle-version>
                          An arbitrary version number for informational purposes. (default: 0.0.1)
  --sdk-name <sdk-name>   Name of the SDK bundle. Defaults to a string composed of Swift version, Linux distribution, Linux
                          release and target CPU architecture.
  --incremental           Experimental: avoid cleaning up toolchain and SDK directories and regenerate the SDK bundle
                          incrementally.
  -v, --verbose           Provide verbose logging output.

So I think setting all of these to .debug level would make sense, with the default log level as .info. --verbose would then change the log level to .debug to show all these messages.

@xtremekforever
Copy link
Contributor Author

So what I ended up doing was setting some of the key actions to .info still, since I think it is useful to know if the generator is performing the essential steps:

$ swift run swift-sdk-generator make-linux-sdk --swift-version 6.0.3-RELEASE --host x86_64-unknown-linux-gnu --t
arget aarch64-unknown-linux-gnu
Building for debugging...
[12/12] Linking swift-sdk-generator
Build of product 'swift-sdk-generator' complete! (2.39s)
2025-01-17T18:33:56-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] Downloading required toolchain packages...
2025-01-17T18:33:57-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] Using downloaded artifacts from cache
2025-01-17T18:33:59-0500 info org.swift.swift-sdk-generator : packageCount=11 [SwiftSDKGenerator] Downloading Ubuntu packages...
2025-01-17T18:34:01-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] Unpacking and copying Swift binaries for the host triple...
2025-01-17T18:34:13-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] Unpacking Swift distribution for the target triple...
2025-01-17T18:34:25-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] Copying Swift core libraries for the target triple into Swift SDK bundle...
2025-01-17T18:34:26-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] Fixing up absolute symlinks...
2025-01-17T18:34:27-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] Generating toolset JSON file...
2025-01-17T18:34:27-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] Generating destination JSON file...
2025-01-17T18:34:27-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] Generating .artifactbundle info JSON file...
2025-01-17T18:34:27-0500 info org.swift.swift-sdk-generator : [SwiftSDKGenerator] 

All done! Install the newly generated SDK with this command:
swift experimental-sdk install ~/swift-sdk-generator/Bundles/6.0.3-RELEASE_ubuntu_jammy_aarch64.artifactbundle

After that, use the newly installed SDK when building with this command:
swift build --experimental-swift-sdk 6.0.3-RELEASE_ubuntu_jammy_aarch64

2025-01-17T18:34:27-0500 info org.swift.swift-sdk-generator : elapsedTime=31 seconds [GeneratorCLI] Generator run finished successfully.

However, when you pass --verbose to the generator, then .debug mode is enabled and everything gets printed! Let me know what you think @MaxDesiatov and @euanh

@xtremekforever xtremekforever marked this pull request as ready for review January 21, 2025 01:29
- This was missed in the last set of changes, but important to note that the generator can now generate Swift SDKs to cross compile between different Linux distributions.
@MaxDesiatov
Copy link
Contributor

@swift-ci test

@MaxDesiatov MaxDesiatov added the enhancement New feature or request label Jan 22, 2025
@xtremekforever
Copy link
Contributor Author

xtremekforever commented Feb 2, 2025

@MaxDesiatov I fixed the merge conflict. Sorry I didn't notice before- I came by a few times and just saw green checkmarks and not the conflict.

Please let me know if there's anything else here you'd like to me look at or refine!

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Feb 5, 2025

LGTM, but I'd like to get some feedback from @euanh and @kateinoigakukun

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@MaxDesiatov MaxDesiatov enabled auto-merge (squash) February 5, 2025 14:52
@MaxDesiatov
Copy link
Contributor

@swift-ci test

@MaxDesiatov MaxDesiatov merged commit c6ebe92 into swiftlang:main Feb 5, 2025
2 of 3 checks passed
@xtremekforever xtremekforever deleted the improvement/structured-logging branch February 5, 2025 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants