Czy istnieje jakieś niebezpieczeństwo w opuszczaniu instrukcji NSLog podczas budowania aplikacji do dystrybucji?
Z jakiegoś powodu, podczas mojego cyklu programistycznego usuwam instrukcje NSLog, które wstawiłem, aby pomóc w debugowaniu. Nie wiem, dlaczego mam ten nawyk, po prostu to robię.
Okazjonalnie, w trakcie tworzenia odkryję, że napotkam problem, który miałem wcześniej, a następnie dodam ponownie starą instrukcję NSLog. A potem kasowanie go ponownie później.
Czy jest jakiś dobry powód do usunięcia wypowiedzi NSLog? Z mojego doświadczenia wynika, że pozostawienie jednego lub dwóch w odrzucenie aplikacji. A ponieważ, z mojej wiedzy, nie rejestrują niczego nigdzie, gdy aplikacja jest w dystrybucji (Proszę mnie poprawić, jeśli się mylę w tej sprawie), nie wydaje się, aby cokolwiek szkodziły. Czy jest jakiś hit, o który powinienem się martwić?
3 answers
To, co robię, to dodawanie makra, które rejestruje tylko wtedy, gdy jestem w trybie debugowania. Umieść to w swoim <APP_NAME>_Prefix.pch
Pliku
#ifdef DEBUG
#define DebugLog( s, ... ) NSLog( @"<%p %@:%d (%@)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, NSStringFromSelector(_cmd), [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DebugLog( s, ... )
#endif
Jako bonus do zwykłego dziennika, otrzymasz nazwę pliku, nazwę Metody i numer linii.
Następnie w informacji o projekcie, dodaj to tylko w kompilacji debugowania. Znajduje się w sekcji User-defined
pod GCC_PREPROCESSOR_DEFINITIONS:
DEBUG
Następnie zastąp dowolny z NSLog ' ów, które masz w swoim projekcie, DebugLog 'em (pobiera te same args co NSLog) i nie będziesz muszę się martwić o wypuszczenie instrukcji debugowania na żywo.
W odpowiedzi na twoje pytanie, logowanie może spowolnić działanie aplikacji i jeśli nie potrzebujesz ich do pomocy debugowania w dziczy, pominęłbym je.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-11-04 14:54:51
Jest (imo) ładny post o tym z możliwym rozwiązaniem.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-11-04 14:53:38
Jeśli masz dużą ilość logów, aplikacja może być wolniejsza. Log do konsoli przetwarzam.
Uzupełnienie odpowiedzi daje, tutaj jeden duży zbiór stałych debugowania, których używamy. Smacznego.
// Uncomment the defitions to show additional info.
// #define DEBUG
// #define DEBUGWHERE_SHOWFULLINFO
// #define DEBUG_SHOWLINES
// #define DEBUG_SHOWFULLPATH
// #define DEBUG_SHOWSEPARATORS
// #define DEBUG_SHOWFULLINFO
// Definition of DEBUG functions. Only work if DEBUG is defined.
#ifdef DEBUG
#define debug_separator() NSLog( @"────────────────────────────────────────────────────────────────────────────" );
#ifdef DEBUG_SHOWSEPARATORS
#define debug_showSeparators() debug_separator();
#else
#define debug_showSeparators()
#endif
/// /// /// ////// /////
#ifdef DEBUG_SHOWFULLPATH
#define debug_whereFull() debug_showSeparators(); NSLog(@"Line:%d : %s : %s", __LINE__,__FILE__,__FUNCTION__); debug_showSeparators();
#else
#define debug_whereFull() debug_showSeparators(); NSLog(@"Line:%d : %s : %s", __LINE__,[ [ [ [NSString alloc] initWithBytes:__FILE__ length:strlen(__FILE__) encoding:NSUTF8StringEncoding] lastPathComponent] UTF8String ] ,__FUNCTION__); debug_showSeparators();
#endif
/// /// /// ////// /////
#define debugExt(args,...) debug_separator(); debug_whereFull(); NSLog( args, ##__VA_ARGS__); debug_separator();
/// /// /// ////// ///// Debug Print Macros
#ifdef DEBUG_SHOWFULLINFO
#define debug(args,...) debugExt(args, ##__VA_ARGS__);
#else
#ifdef DEBUG_SHOWLINES
#define debug(args,...) debug_showSeparators(); NSLog([ NSString stringWithFormat:@"Line:%d : %@", __LINE__, args ], ##__VA_ARGS__); debug_showSeparators();
#else
#define debug(args,...) debug_showSeparators(); NSLog(args, ##__VA_ARGS__); debug_showSeparators();
#endif
#endif
/// /// /// ////// ///// Debug Specific Types
#define debug_object( arg ) debug( @"Object: %@", arg );
#define debug_int( arg ) debug( @"integer: %i", arg );
#define debug_float( arg ) debug( @"float: %f", arg );
#define debug_rect( arg ) debug( @"CGRect ( %f, %f, %f, %f)", arg.origin.x, arg.origin.y, arg.size.width, arg.size.height );
#define debug_point( arg ) debug( @"CGPoint ( %f, %f )", arg.x, arg.y );
#define debug_bool( arg ) debug( @"Boolean: %@", ( arg == YES ? @"YES" : @"NO" ) );
/// /// /// ////// ///// Debug Where Macros
#ifdef DEBUGWHERE_SHOWFULLINFO
#define debug_where() debug_whereFull();
#else
#define debug_where() debug(@"%s",__FUNCTION__);
#endif
#define debug_where_separators() debug_separator(); debug_where(); debug_separator();
/// /// /// ////// /////
#else
#define debug(args,...)
#define debug_separator()
#define debug_where()
#define debug_where_separators()
#define debug_whereFull()
#define debugExt(args,...)
#define debug_object( arg )
#define debug_int( arg )
#define debug_rect( arg )
#define debug_bool( arg )
#define debug_point( arg )
#define debug_float( arg )
#endif
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-11-04 19:29:58