in project, redirecting nslog
data file using code
freopen([filepath cstringusingencoding:nsutf8stringencoding],"a+",stderr);
we got issue if keep on writing data file size may increased hugely, want restrict data. lets after file size reached 2mb want clear old data , write new data.
how can it, how can check file size in run time.
for can use attributesofitematpath:
method of nsfilemanager
nserror *err; nsdictionary *fileattributes = [[nsfilemanager defaultmanager] attributesofitematpath:filepath error:&err]; nsnumber *filesize = [fileattributes objectforkey:nsfilesize]; if(//check whether size above 2 mb) { //remove old content either removing file or clearing [[nsfilemanager defaultmanager] removeitematpath:filepath error:&err]; } else { //add data freopen([filepath cstringusingencoding:nsutf8stringencoding],"a+",stderr); }
Comments
Post a Comment