Open Tibbs opened 4 years ago
That's a very good question. This is interesting because last time I checked the call was optimized out completely. This may be an issue with the Swift optimizer which eliminates the call a point-of-log, but may not remove the closure it auto-generates from the string... Thanks for pointing this out!
As of now, I don't have a hint at how one could fix it.
Thank you @fpillet. This is what I thought. Hopefully, someone will suggest an easy fix. I will look into this as well.
I couldn't find a solution for the text in the closure, but I also noticed that #file and #function attributes are behaving the same way, leaving the absolute path and function name in the binary. It increases the size of the binary and exposes the user name of the developer. It is much easier to fix. For example, changing the code in NSLogger.swift from this:
public func log(_ domain: Domain,
_ level: Level,
_ message: @autoclosure () -> String,
_ file: String = #file,
_ line: Int = #line,
_ function: String = #function) {
whenEnabled {
LogMessage_noFormat(file, line, function, domain.rawValue, level.rawValue, message())
}
}
to this resolves this issue:
public func log(_ domain: Domain,
_ level: Level,
_ message: @autoclosure () -> String,
_ file: String = "",
_ line: Int = #line,
_ function: String = "") {
whenEnabled {
let filePath = #file
let functionName = #function
LogMessage_noFormat(filePath, line, functionName, domain.rawValue, level.rawValue, message())
}
}
Pull request to remove #file and #function strings from release binary
In Objective C if I use the macros defined in NSLogger.h completely disable NSLogger and logging message strings don't show up in the release binary. In Swift, in the release binary, the logging functionality is disabled but the logging message strings remain hardcoded in the released binary. Is there any way to strip those logging strings completely from the release binary?