因此,在本地通过xcode
在开发人员中或使用SPM
进行编译时,控制台日志会按预期显示。
即在本地使用SPM
一切都很好
swift build --configuration release
.build/release/Myapp # prints to console
但是当我通过在ECS(我想是Linux)上运行的docker容器运行可执行文件时,我看不到我的Swift代码生成的日志,但是我确实看到stderr被第三方库打印(即libssl正在打印错误)以及启动应用程序时的Shell日志
例如:
Docker文件
FROM swift
WORKDIR /app
COPY Package.swift ./
COPY Sources ./Sources
COPY Tests ./Tests
RUN swift package clean
RUN swift build --configuration release
RUN chmod +x start.sh
CMD ["start.sh"] # just a wrapper to see if "echo" works
在start.sh中
# prints as expected
echo "hi this will print"
# nothing in the executable will print though
.build/release/MyApp
最佳答案
有同样的问题,我提起了雷达,苹果回答了:
import Darwin
setbuf(stdout, nil)
关于swift - swift “print”未出现在STDOut中,但是在ECS上的docker中运行时,第三方c库日志会显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57095407/