Swift "Print" Doesn't Appear in Stdout But 3Rd Party C Library Logs Do When Running in Docker on Ecs

swift print doesn't appear in STDOut but 3rd party c library logs do when running in docker on ECS

Had the same issue, I filed a radar, and Apple answered:

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: Extending functionality of print() function

You can overshadow the print method from the standard library:

public func print(items: Any..., separator: String = " ", terminator: String = "\n") {
let output = items.map { "*\($0)" }.joined(separator: separator)
Swift.print(output, terminator: terminator)
}

Since the original function is in the standard library, its fully qualified name is Swift.print



Related Topics



Leave a reply



Submit