Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6545501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:35:35+00:00 2026-05-25T11:35:35+00:00

I am currently using NSLog everywhere in my code just to test it, is

  • 0

I am currently using NSLog everywhere in my code just to test it, is there a better and more professional way besides using standard NSLog? Mind sharing what other professional objective-C coders use to do logging while debugging?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:35:37+00:00Added an answer on May 25, 2026 at 11:35 am

    Here’s my logging class. It just macros around NSLog but it allows you to have switchable levels. I borrowed and modified this from others but can’t remember where – I wish I could give props. The comments are a good guide to use. Hope it helps.

    /*
     * There are three levels of logging: debug, info and error, and each can be enabled independently
     * via the ENLOGGING_LEVEL_DEBUG, ENLOGGING_LEVEL_INFO, and ENLOGGING_LEVEL_ERROR switches below, respectively.
     * In addition, ALL logging can be enabled or disabled via the ENLOGGING_ENABLED switch below.
     *
     * To perform logging, use any of the following function calls in your code:
     *
     * ENDebug(fmt, …) – will print if ENLOGGING_LEVEL_DEBUG is set on.
     * ENInfo(fmt, …) – will print if ENLOGGING_LEVEL_INFO is set on.
     * ENHeading(fmt, …) – will print if ENLOGGING_LEVEL_INFO is set on.
     * ENError(fmt, …) – will print if ENLOGGING_LEVEL_ERROR is set on.
     *
     * Each logging entry can optionally automatically include class, method and line information by
     * enabling the ENLOGGING_INCLUDE_CODE_LOCATION switch.
     *
     * Logging functions are implemented here via macros, so disabling logging, either entirely,
     * or at a specific level, removes the corresponding log invocations from the compiled code,
     * thus completely eliminating both the memory and CPU overhead that the logging calls would add.
     */
    
    #define ENLOGGING_ENABLED 1
    
    // Set any or all of these switches to enable or disable logging at specific levels.
    
    #define ENLOGGING_LEVEL_DEBUG 1
    #define ENLOGGING_LEVEL_INFO 1
    #define ENLOGGING_LEVEL_ERROR 1
    
    // Set this switch to set whether or not to include class, method and line information in the log entries.
    #define ENLOGGING_INCLUDE_CODE_LOCATION 0
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //
    // Implementation
    //
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    #if !(defined(ENLOGGING_ENABLED) && ENLOGGING_ENABLED)
    #undef ENLOGGING_LEVEL_DEBUG
    #undef ENLOGGING_LEVEL_INFO
    #undef ENLOGGING_LEVEL_ERROR
    #endif
    
    // Logging format
    #define ENLOG_FORMAT_NO_LOCATION(fmt, lvl, ...) NSLog((@"[%@] " fmt), lvl, ##__VA_ARGS__)
    #define ENLOG_FORMAT_WITH_LOCATION(fmt, lvl, ...) NSLog((@"%s [Line %d] [%@] " fmt), __PRETTY_FUNCTION__, __LINE__, lvl, ##__VA_ARGS__)
    
    #if defined(ENLOGGING_INCLUDE_CODE_LOCATION) && ENLOGGING_INCLUDE_CODE_LOCATION
    #define ENLOG_FORMAT(fmt, lvl, ...) ENLOG_FORMAT_WITH_LOCATION(fmt, lvl, ##__VA_ARGS__)
    #else
    #define ENLOG_FORMAT(fmt, lvl, ...) ENLOG_FORMAT_NO_LOCATION(fmt, lvl, ##__VA_ARGS__)
    #endif
    
    // Debug level logging
    
    #if defined(ENLOGGING_LEVEL_DEBUG) && ENLOGGING_LEVEL_DEBUG
    #define ENDebug(fmt, ...) ENLOG_FORMAT(fmt, @"debug", ##__VA_ARGS__)
    #else
    #define ENDebug(...)
    #endif
    
    // Info level logging
    
    #if defined(ENLOGGING_LEVEL_INFO) && ENLOGGING_LEVEL_INFO
    #define ENInfo(fmt, ...) ENLOG_FORMAT(fmt, @"info", ##__VA_ARGS__)
    #define ENHeading(fmt, ...) ENLOG_FORMAT(@"####################  " fmt "  ####################", @"HD", ##__VA_ARGS__)
    #else
    #define ENInfo(...)
    #define ENHeading(...)
    #endif
    
    // Error level logging
    
    #if defined(ENLOGGING_LEVEL_ERROR) && ENLOGGING_LEVEL_ERROR
    #define ENError(fmt, ...) ENLOG_FORMAT(fmt, @"***ERROR***", ##__VA_ARGS__)
    #else
    #define ENError(...)
    #endif
    
    #if defined(ENLOGGING_LEVEL_ERROR) && ENLOGGING_LEVEL_ERROR
    #define ENResult(result, error) if (result == NO) ENError("%@", error)
    #else
    #define ENResult(...)
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there a way to nslog how much memory your application is currently using?
I am currently using some pretty standard code to enumerate assets in a group.
I am currently using Windows Server 2008 Standard and have several Hyper V machines.
I'm currently using this code NSHost *host = [NSHost hostWithAddress:hostname]; if (host == nil)
Currently I am using the following code to parse the JSON link sent. This
I'm currently using -respondsToSelector: like so: if (![moviePlayer respondsToSelector:@selector(currentPlaybackTime)]) { NSLog(@Cannot get current playbackTime
I am using a for loop to (currently) NSLog the contents of a NSArray.
Currently using System.Web.UI.WebControls.FileUpload wrapped in our own control. We have licenses for Telerik. I
Currently using the HTTPServletRequest class and specifically the .getQueryString method to retrieve an inputted
Currently using Google Analytics as a supplement to our paid tracking software, but neither

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.