Skip to content

Instantly share code, notes, and snippets.

@gdavis
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdavis/870371272ffc28ee15e4 to your computer and use it in GitHub Desktop.
Save gdavis/870371272ffc28ee15e4 to your computer and use it in GitHub Desktop.
GDILog - Replacement for NSLog
//
// GDILog.h
// GDILog
//
// Created by Grant Davis on 8/18/14.
// Copyright (c) 2014 Grant Davis Interactive, LLC. All rights reserved.
//
#ifdef DEBUG
#include <string.h>
#define FILE (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define GDILog(...) printf("%s (%d) -> %s\r", FILE, __LINE__, [[NSString stringWithFormat:__VA_ARGS__] UTF8String])
#else
#define GDILog(...)
#endif
@gdavis
Copy link
Author

gdavis commented Aug 18, 2014

GDILog is an alternative to NSLog that provides a few nice things:

  • Remove timestamp and project name
  • Adds the class name and line number the log originated from
  • Disables logging when not in DEBUG mode.
  • Makes a much cleaner and useful print log!

@gdavis
Copy link
Author

gdavis commented Aug 18, 2014

Example:

GDILog(@“Hello, %@!”, @“World”);

Prints:
AppDelegate.m (20) -> Hello, World!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment