Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
4
Question by soulburner · Mar 14, 2013 at 10:36 AM · iosbuildconsoledebug.logoutput

Get Debug.Log output in the working iOS build

I've got a question.

I have an application that is uploaded to AppStore. And I have a device (iPhone, jailbroken) with this app installed. Is there any way to see what "Debug.Log" is outputting in the build?

I've found only way to see the console through "iPhone Configuration Utility", but there are only some system outputs in that console.

Is there any chance to see something similar to what I see when I build a project directly to my phone and then look at xCode's "all output" ?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
9

Answer by Mozgoid · Dec 05, 2014 at 10:24 AM

You can use log callbacks to save log to file, or send it to your server.

 public class LogHandler : MonoBehaviour
 {
     private StreamWriter _writer;
     void Awake()
     {
         _writer = File.AppendText("log.txt");    
         _writer.Write("\n\n=============== Game started ================\n\n");
         DontDestroyOnLoad(gameObject);
         Application.RegisterLogCallback(HandleLog);
     }
 
     private void HandleLog(string condition, string stackTrace, LogType type)
     {
         var logEntry = string.Format("\n {0} {1} \n {2}\n {3}"
             , DateTime.Now, type, condition, stackTrace);
         MyServer.SendLog(logEntry);
         _writer.Write(logEntry);
     }
 
     void OnDestroy()
     {
         _writer.Close();
     }
 }


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
9

Answer by sunshineblocks · Nov 13, 2016 at 10:43 PM

Hey so -- good answer by @Mozgold but -- well, first off let me note that Application.RegisterLogCallback has now been replaced -- any one looking to use @Mozgold's answer should use Application.logMessageReceivedThreaded or Application.logMessageReceived -- see this thread http://answers.unity3d.com/questions/1009660/how-to-use-applicationlogmessagereceived-for-loggi.html

I had the same problem, but preferred instead to use a bridge to pipe Debug.Log messages to NSLog. The downside of this approach is that, in XCode's console, you see the messages twice. The advantage is that, when running a TestFlight'd build, I see the messages live as they happen in XCode's Window / Devices log when the app is running on my selected device.

STEP 1 -- register a callback so that Debug.Log's are piped to method in my iOS plugin

     public void OnEnable() {
         // Debug.LogWarning("------ ------ Registered log callback----- ---------");
         Application.logMessageReceived += IOSPlugin.LogToiOS;
     }
 
     public void OnDisable() {
         Application.logMessageReceived -= IOSPlugin.LogToiOS;
     }

STEP 2 -- implement method in my iOSPlugin to pipe these calls to the native app

 using UnityEngine;
 using System.Collections;
 using System.Runtime.InteropServices;
 
 public class IOSPlugin : MonoBehaviour {
 
     #if UNITY_IPHONE
     [DllImport ("__Internal")]
     private static extern void _logToiOS(string debugMessage);
     #endif
 
     public static void LogToiOS(string logString, string stackTrace, LogType type) {
         // We check for UNITY_IPHONE again so we don't try this if it isn't iOS platform.
         #if UNITY_IPHONE
         // Now we check that it's actually an iOS device/simulator, not the Unity Player. You only get plugins on the actual device or iOS Simulator.
         if (Application.platform == RuntimePlatform.IPhonePlayer) {
             _logToiOS(logString + "\n===============\n" + stackTrace);
         }
         #endif
     }
 }

STEP 3 -- implement a method in my iOS app's AppController.mm to pipe this to NSLog -- you should be able to just directly drop this in your AppController.mm and be all set

 extern "C" {
   
     void _logToiOS(const char* debugMessage) {
          NSLog(@"Received _logToiOS %@", [NSString stringWithUTF8String:debugMessage]);
     }
 
 }



Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dave_oak · Jan 16, 2018 at 10:27 AM 0
Share

Sweet solution, thanks! In my case step 3 had to go in UnityAppController.mm

avatar image tylearymf · Apr 17, 2018 at 02:04 AM 0
Share

not jailbreak : you can use mac to view log(https://github.com/libimobiledevice/libimobiledevice) jailbreak : install oslog in cydia(cydia.saurik.com/package/net.limneos.oslog),and use ssh to connect your phone

avatar image
4

Answer by unimechanic · Nov 22, 2013 at 03:10 PM

First build your iOS app with "Development Build" enabled. In Unity 4, Debug.Log() output is shown in the XCode's debug Console. Notice that this is NOT the Console in the Organizer, which shows the device events, but it's the Console that is shown at the bottom of the main window, which is called Debug area. The Organizer's Device Logs is useful to obtain the crash logs when the app is executing out of XCode.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sunshineblocks · Nov 13, 2016 at 10:30 PM 0
Share

I think the OP knows that.... the question is how to make messages pop up in the XCode / Devices console to, for example, debug an issue that only shows in a TestFlight'd build (or some other build that you can't attach the standard debug console to).

avatar image
1

Answer by yashesh · Mar 14, 2013 at 11:32 AM

You can check that with another option. Connect you phone to your MAC which have xCode install. Now open xCode and from xCode open Organizer. From Organizer select **Devices*tab and in that you can see you device in that. And from your selected device select Console* in that you can see the device log.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image soulburner · Mar 14, 2013 at 03:31 PM 1
Share

No, that's helpless, sorry. This console is the same console you can see in iPhone Configuration Utility. And there are only system messages, but no my Debug.Log outputs :(

avatar image
0

Answer by Deepscorn · Apr 08, 2020 at 09:01 PM

You can redirect NSLog (and so, what you write with Debug.Log, will also be redirected) to file adding something like that to your native ios code:

 - (void)redirectLogToDocument
 {
      NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [allPaths objectAtIndex:0];
      NSString *pathForLog = [documentsDirectory stringByAppendingPathComponent:@"yourFile.txt"];
 
      NSLog(@"redirectLogToDocument: %@", pathForLog);
     
      freopen([pathForLog cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
     freopen([pathForLog cStringUsingEncoding:NSASCIIStringEncoding],"a+",stdout);
 }
 
 // usage:
 
     if (!isatty(STDERR_FILENO)) { // if debugger not attached
         [self redirectLogToDocument]; // redirect logs
     }
 

Then you can take your file using Window -> Devices & Simulators -> select your device -> select your app -> press settings button below -> select "download container" from dropdown. xcappdata file will be saved. Reveil in finder, click right mouse button, click "show package contents", then go to Documents folder. There will be your file.

Screenshot better describes that: https://stackoverflow.com/a/6121649/884195

Based on: https://stackoverflow.com/a/8379047/884195 https://stackoverflow.com/a/9620429/884195

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Does anyone have this Problem? - iOS build crashes on Unity 2020.1 1 Answer

How to prepare your scene to build and run? 1 Answer

Launch Xcode build from iOS application project. 0 Answers

BuildPlayer for iOS - progress bar never closes 1 Answer

IOS Unity Cloud build failed : Invalid bitcode version 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges