Skip to content

Completely disable and hide NSLogger strings in Swift #290

Open
@Tibbs

Description

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?

Activity

fpillet

fpillet commented on Feb 10, 2020

@fpillet
Owner

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

Tibbs commented on Feb 10, 2020

@Tibbs
Author

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

Tibbs

Tibbs commented on Feb 13, 2020

@Tibbs
Author

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

Tibbs commented on Jun 16, 2020

@Tibbs
Author

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Completely disable and hide NSLogger strings in Swift · Issue #290 · fpillet/NSLogger