Latest 1.0.1
Homepage https://github.com/NRGRepo/NRGLog
License Apache
Platforms ios 4.0, requires ARC
Authors

GDXLog

Simple iOS managed logging library in Objective-C.

GDXLog uses standard NSLog() function so you should not redefine this macro by yourself.

Adding GDXLog to your project

CocoaPods

CocoaPods is the recommended way to add GDXLog to your project.

  1. Add a pod entry for GDXLog to your Podfile pod 'GDXLog'
  2. Install the pod(s) by running pod install.
  3. Include GDXLog wherever you need it with #import "GDXLog.h".

Source files

Alternatively you can directly add the GDXLog.h and GDXLog.m source files to your project.

  1. Download the latest code version or add the repository as a git submodule to your git-tracked project.
  2. Open your project in Xcode, then drag and drop GDXLog.h and GDXLog.m onto your project (use the "Product Navigator view"). Make sure to select Copy items when asked if you extracted the code archive outside of your project.
  3. Include GDXLog wherever you need it with #import "GDXLog.h".

Usage

All your code can be separated on the virtual groups, for example, network requests, UI animation cases, etc. GDXLog helps you to log these parts independently with the single GDXLog management code.

// define your tokens
#define LOG_TOKEN_NETWORK @"network"

// log
[GDXLog logToken:LOG_TOKEN_NETWORK format:@"My network request RAW: %@", yourRaw];

Tokens and Groups

There are difference between token phrases and token groups.

  • Token is an exact phrase that identifies your actions logical group.
  • Group of tokens is a physical group which allows you to enable or disable your several tokens at the same time.

Let’s see how it works.

It’s strongly recommended to define your tokens and groups in a separated header file, for example, GDXLogWrapper.h.

Let your app working with network, so it can send requests and receive responses. Also you may want to manage network connection state. It is convenient to make three separated tokens for each action (request and response) and group them into networking group.

This is how it can be implemented with my recommendations:

#ifndef GDXLogWRAPPER_H
#define GDXLogWRAPPER_H

#pragma mark - Groups

// networking
#define LOG_GROUP_NETWORK       @"network"
#define LOG_GROUP_NETWORK_QUERY LOG_GROUP_NETWORK ".query"

#pragma mark - Tokens

// networking
#define LOG_TOKEN_NETWORK_CONNECTION     LOG_GROUP_NETWORK ".connection"
#define LOG_TOKEN_NETWORK_QUERY_REQUEST  LOG_GROUP_NETWORK_QUERY ".request"
#define LOG_TOKEN_NETWORK_QUERY_RESPONSE LOG_GROUP_NETWORK_QUERY ".response"

#endif

Now you have two groups, one of them is a sub-group of another, and three tokens in these groups. It’s simple to use this configuration:

[GDXLog logToken:LOG_TOKEN_NETWORK_CONNECTION 
          format:@"Connection established."];
[GDXLog logToken:LOG_TOKEN_NETWORK_QUERY_REQUEST 
          format:@"Request sent: %@", requestRaw];
[GDXLog logToken:LOG_TOKEN_NETWORK_QUERY_RESPONSE 
          format:@"Response received: %@ (error: %@)", responseRaw, error];

The main benefit of joining your tokens into groups is that you can disable any group at any moment, and all your token phrases which contains a specified group name in their names will not be printed in logs until you enable this group again.

For example, this code line

[[GDXLog instance] setTokenGroup:LOG_GROUP_NETWORK_QUERY enabled:NO];

will disable tokens LOG_TOKEN_NETWORK_QUERY_REQUEST and LOG_TOKEN_NETWORK_QUERY_RESPONSE, but will not disable global network group, so token LOG_TOKEN_NETWORK_CONNECTION will be accessible.

You are free to use exact token phrases without groups if this is more convenient for you, but it is strongly recommended to use groups for more flexible logging management.

Additional Abilities

You can configure GDXLog messages display mode by setting custom bitmask options for the options property. Here are all available values:

  • GDXLogOptionNone – means no options enabled. GDXLog will display simple messages with your format strings and arguments, no more. It equals zero and added just for convenient naming.
  • GDXLogOptionDisplayToken – if enabled, token name will be printed before each log message.
  • GDXLogOptionDisplayMethod – prints a method which is currently executing.

Note that all these options are enabled by default.

The shortest configuration with no options set will print this:

// in your global configuration file, or, for example, in AppDelegate.m
[GDXLog instance].options = GDXLogOptionNone;

// then somewhere in your code
[GDXLog logToken:LOG_TOKEN_NETWORK_CONNECTION format:@"Connection established."];

Console output:

| Connection established.

Now let’s compare this with all options enabled:

[GDXLog logToken:LOG_TOKEN_NETWORK_CONNECTION format:@"Connection established."];

Console output:

| network.connection | [AppDelegate application:didFinishLaunchingWithOptions:] | Connection established.

Note that you can change your logging options configuration at any time, it will affect only the future logToken:format: method calls.

Thread Safety

GDXLog is completely thread safe, you are free to use it in your asynchronous threads. Just remember that GDXLog uses standard NSLog() function, so do not forget to disable global logging by disabling loggingEnabled property on a production project scheme to avoid performance issues.

License

Apache. See LICENSE for details.

Latest podspec

{
    "name": "NRGLog",
    "version": "1.0.1",
    "summary": "Simple iOS managed logging library in Objective-C",
    "homepage": "https://github.com/NRGRepo/NRGLog",
    "license": {
        "type": "Apache",
        "file": "LICENSE"
    },
    "authors": {
        "Georgiy Malyukov": ""
    },
    "source": {
        "git": "https://github.com/NRGRepo/NRGLog.git",
        "tag": "1.0.1"
    },
    "social_media_url": "http://deadlineru.livejournal.com",
    "platforms": {
        "ios": "4.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "test": [
            "Pod/Assets/*.png"
        ]
    }
}

Pin It on Pinterest

Share This