Skip to content
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

Completely disable and hide NSLogger strings in Swift #290

Open
Tibbs opened this issue Feb 10, 2020 · 4 comments
Open

Completely disable and hide NSLogger strings in Swift #290

Tibbs opened this issue Feb 10, 2020 · 4 comments

Comments

@Tibbs
Copy link

Tibbs commented Feb 10, 2020

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?

@fpillet
Copy link
Owner

fpillet commented Feb 10, 2020

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.

@Tibbs
Copy link
Author

Tibbs commented Feb 10, 2020

Thank you @fpillet. This is what I thought.
Hopefully, someone will suggest an easy fix. I will look into this as well.

@Tibbs
Copy link
Author

Tibbs commented Feb 13, 2020

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())
        }
    }

@Tibbs
Copy link
Author

Tibbs commented Jun 16, 2020

Pull request to remove #file and #function strings from release binary
#292

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants