Customized logging

You can implement your own logging system.

In addition to logging by using predefined notifications, you can implement a logging system that uses your log messages and messages that are generated by TVSDK. For more information about predefined notifications, see The Notification System. You can use these logs to troubleshoot your player applications and to provide better understanding of the playback and advertising workflow.

Customized logging uses a shared singleton instance of the PSDKPTLogFactory, which provides a mechanism to log messages to multiple loggers. You define and add (register) one or more loggers to the PTLogFactory. This allows you to define multiple loggers with custom implementations, such as a console logger, a web logger, or a console history logger.

TVSDK generates log messages for many of its activities, which the PTLogFactory forwards to all registered loggers. Your application can also generate custom log messages, which are forwarded to all registered loggers. Each logger can filter the messages and take appropriate action.

There are two implementations for PTLogFactory:

  • For listening to logs.
  • For adding logs to a PTLogFactory.

Listen to logs

To register for listening to logs:

  1. Implement a custom class that follows the protocol PTLogger:

    @implementation PTConsoleLogger
    
    + (PTConsoleLogger *) consoleLogger {
        return [[[PTConsoleLogger alloc] init] autorelease];
    }
    
    - (void)logEntry:(PTLogEntry *)entry {
        //Log the message to the console using NSLog
        NSLog(@"[%@] %@", entry.tag, entry.message);
    }
    
    @end
    
  2. To register the instance to receive logging entries, add an instance of the PTLogger to the PTLoggerFactory:

    PTConsoleLogger *logger = [PTConsoleLogger consoleLogger];
    // Either use the addLogger method:
    [[PTLogFactory sharedInstance] addLogger:(logger)]
    
    //Or replace the preceding line with this macro for ease of use
    //PTLogAddLogger(logger);
    
    

Here is an example of filtering logs by using the PTLogEntry type:

@implementation PTConsoleLogger

+ (PTConsoleLogger *) consoleLogger {
    return [[[PTConsoleLogger alloc] init] autorelease];
}

- (id) init {
    self = [super init];

    if (self) {
        self.logLevel = PTLogEntryTypeInfo;
    }

    return self;
}

- (void)logEntry:(PTLogEntry *) entry {
    //Filtering the entry by log level
    if (entry.type < _logLevel) {
        return;
    }

    //Log the message to the console using NSLog NSLog(@"[%@] %@", entry.tag, entry.message);
}

@end

Add new log messages

To register to listen to logs:

  1. Create a new PTLogEntry and add it to thePTLogFactory:

    You can manually instantiate a PTLogEntry and add it to the PTLogFactory shared instance or use one of the macros to accomplish the same task.

    Here is an example of logging using the PTLogDebug macro:

// The following line creates an instance of PTLogEntry with type PTLogEntryDebug,
// tag "DEBUG_PLAYBACK", and message "Playback has started".
// Then the PTLogEntry is automatically added to the PTLogFactory

PTLogDebug(@"[DEBUG_PLAYBACK] Playback has started");

On this page