When a real machine or a real machine is not connected to a computer, you can output the log information to a file.
1. Set the log file path
1 -(Nsstring *) logfilepath {
2 // Non-Jailbreak path
3 # Ifndef Crack
4 Nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes );
5 Nsstring * documentsdirectory = [paths objectatindex: 0 ];
6 // Jailbreak path
7 # Else
8 Nsstring * documentsdirectory = @" /Var/root/Media/Xiaodao/ " ;
9 # Endif
10 Nsstring * logdir = [documentsdirectory stringbyappendingpathcomponent: @" Logs " ];
11 Bool isdir = yes;
12 // If the logs Folder does not exist, create
13 If ([[Nsfilemanager defaultmanager] fileexistsatpath: logdir isdirectory: & isdir] = No)
14 {
15 [[Nsfilemanager defaultmanager] createdirectoryatpath: logdir withintermediatedirectories: Yes attributes: Nil error: Nil];
16 }
17 // Take the day as the file name, and the file name suffix is. Log
18 Nsstring * filename = [nsstring stringwithformat: @" % @. Log " , [Nsdate date];
19 Nsstring * logpath = [logdir stringbyappendingpathcomponent: Filename];
20 Return Logpath;
21 }
2. Start printing logs
1-(Void) Startlog {
2Freopen ([[self logfilepath] cstringusingencoding: nsasciistringencoding],"A +", Stderr );
3}
Freopen redirection Printing
Stderr is the standard error message
3. Disable log printing.
1-(Void) Finishlog {
2Fflush (stderr );
3Dup2 (DUP (stderr_fileno), stderr_fileno );
4Close (DUP (stderr_fileno ));
5}
4. Clear log files
1-(Bool) deletelogfile {
2Bool success = [[nsfilemanager defaultmanager] removeitematpath: [self logfilepath] error: Nil];
3ReturnSuccess;
4}