gpt4 book ai didi

swift - swift “print”未出现在STDOut中,但是在ECS上的docker中运行时,第三方c库日志会显示

转载 作者:行者123 更新时间:2023-12-02 21:07:26 26 4
gpt4 key购买 nike

因此,在本地通过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

最佳答案

有同样的问题,我提起了雷达,苹果回答了:

When piped to another process print is buffered, so no characters appear until the buffer is filled up. (When piped to the terminal we only buffer until we hit a newline.)

You can get the behavior you want by calling setbuf(stdout, nil) once at startup:

 import Darwin
setbuf(stdout, nil)

关于swift - swift “print”未出现在STDOut中,但是在ECS上的docker中运行时,第三方c库日志会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57095407/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com