-
Notifications
You must be signed in to change notification settings - Fork 7
/
Logger.m
44 lines (35 loc) · 1.08 KB
/
Logger.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Logger.m
// Snap
//
// Created by Abdullah Bakhach on 10/2/12.
// Copyright (c) 2012 Hollance. All rights reserved.
//
#import "Logger.h"
@implementation Logger
+(void)Log:(NSString *)content
{
if (FILE_LOG_MODE)
[Logger logToFile:content];
else
[Logger logToConsole:content];
}
+(void)logToFile:(NSString *)content
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString* docDir = [paths objectAtIndex:0];
NSString * logFile = [docDir stringByAppendingString:@"/log.txt"];
content = [content stringByAppendingString:@"\n"];
NSData *dataToWrite = [content dataUsingEncoding: NSUTF8StringEncoding];
NSFileHandle* outputFile = [NSFileHandle fileHandleForWritingAtPath:logFile];
[outputFile seekToEndOfFile];
[outputFile writeData:dataToWrite];
[outputFile closeFile];
NSLog(content);
}
+(void)logToConsole:(NSString *)content
{
NSLog(content);
}
@end