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

  • Home
  • SEARCH
  • 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 3277252
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:20:53+00:00 2026-05-17T19:20:53+00:00

Suppose you have the code of a Cocoa app which logs its own messages

  • 0

Suppose you have the code of a Cocoa app which logs its own messages through NSlogs and printfs to the Console output. My goal is to redirect all this output into a separate NSWindow in a NSView.

How can I achieve this in a way that

  • minimizes the amount of code to rewrite
  • makes it possible to revert back
  • maximizes the reuse of written code

(the usual software engineering guide lines)?

  • 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-17T19:20:53+00:00Added an answer on May 17, 2026 at 7:20 pm

    Here is the solution I came up with:

    1. Create an NSWindowController that has a NSTextView as an outlet (let’s call this A)
    2. Create a Singleton class (let’s call this B) that encapsulates an A object and provides some methods for sending strings to A (which appends it to its NSTextView) by reading a file (which contains all the loggings) using readInBackgroundAndNotify from NSFileHandle. When notified it calls the appending method. It has a method for starting the logging on file as well, which uses freopen(3) to redirect some stream (stderr and stdout atm) to a file in append mode.
    3. In the project just call the starting logging method of B (no needs of instantiation, but I guess it really does not matter) after importing it.

    This solution was created considering both Joshua Nozzi’s answer and tlindner’s one, and combines them. I have and encapsulated solution that respects the three requests in the question (I have to add only a line of code, I can revert back easily and I can use this solution in other apps too). I noticed that maybe sometimes it can be wrong to have an NSWindowController encapsulated this way (whereas all the other ones are managed by some super-controller).

    I finally opted for the file solution since it is very easy to implement and more Cocoa-like than tlindner’s one. Also it gives the opportunity to have a logging file that persists on the disk. But of course I may have missed something, point that to me in the comments please ^^

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some processing in my Cocoa app that sometimes ends up calling through
Suppose I have code that maintains a parent/children structure. In such a structure I
Suppose I have the code like this: <table> <tr> <th>name</td> <th>price</td> </tr> <tr> <td>a</td>
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Suppose i have the code snippet as follows : ( clarification purpose/not well formed
Suppose I have this code: String encoding = UTF-16; String text = [Hello StackOverflow];
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
Suppose I have the following code to collect all the possible combinations. abArray =
Suppose I have the following code: foreach(string str in someObj.GetMyStrings()) { // do some
Suppose I have this jQuery code. $(document).delegate('a[title]', 'click', function(event) { var txt = //

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.