iosswiftxcodeloggingoslog

How can I disable a certain oslog log level?


For the following function:

let authenticationLogger = OSLog(subsystem: "com.Company.AppNameQA" ?? "Empty bundleIdentifier", category: "Authenticaiton)

What should I do if I want to disable/enable a certain log level?

Currently with the API the only thing that I'm able to access is the isEnabled fucntion:

authenticationLogger.isEnabled(.error) 

which just returns whether it's enabled or not.


Solution

  • I haven't tried this yet. But I believe this is the solution

    Reading from docs.

    Under the section of:

    Customizing Logging Behavior While Debugging

    Logging behavior is normally governed by the system. However, while debugging in macOS, you can enable different logging levels for a subsystem using the log command-line tool’s config argument while logged in as root. See Listing 5, which shows how to enable debug-level logging for a subsystem.

    Enabling debug-level logging for a subsystem

    $ sudo log config --mode "level:debug" --subsystem com.your_company.your_subsystem_name
    

    Use the log tool’s status argument to check the current logging level of a subsystem.

    Checking the log level of a subsystem

    $ sudo log config --status --subsystem com.your_company.your_subsystem_name
    Mode for 'com.your_company.your_subsystem_name'  DEBUG
    

    You can also override the logging behavior of a specific subsystem by creating and installing a logging configuration profile property list file in the /Library/Preferences/Logging/Subsystems/ directory. Name the file using an identifier string, in reverse DNS notation, representing the subsystem. For example, com.your_company.your_subsystem_name.plist. Next, add one or more settings dictionaries to the top level of the file. A DEFAULT-OPTIONS settings dictionary defines global behavior settings for the entire subsystem. Category settings dictionaries define behavior for specific categories of messages within the subsystem.

    Top level structure of a logging profile

    <dict>
        <key>DEFAULT-OPTIONS</key>
        <dict>
           <!-- GLOBAL SUBSYSTEM OR PROCESS SETTINGS -->
        </dict>
        <key>CategoryName</key>
        <dict>
           <!-- CATEGORY SETTINGS -->
        </dict>
    </dict>
    

    In a nutshell, you can't change the log level from you code in production. You can only change it during debugging. What use can it have? I'm not sure!