malkomalko
9/10/2014 - 9:59 PM

Gemfile

class PapertrailLogger < DDAbstractLogger
  attr_accessor :host, :port

  def initWithHost(host, port:port)
    init
    @host = host
    @port = port
    @app_version = NSBundle.mainBundle.objectForInfoDictionaryKey(KCFBundleVersionKey)

    return self
  end

  def self.sharedInstance(host, port)
    Dispatch.once do
      @logger ||= PapertrailLogger.alloc.initWithHost(host, port:port.to_i)
    end
    @logger
  end

  def logMessage(msg)
    udpSocket = GCDAsyncUdpSocket.alloc.initWithDelegate(nil, delegateQueue:Dispatch::Queue.main)
    message = msg.logMsg
    ts = Time.now.strftime("%b %e %H:%M:%S")
    email = App.delegate.current_user.email if App.delegate.current_user
    formatted_str = "<22>#{ts} APPNAME #{@app_version}: #{message}"
    udpSocket.sendData(formatted_str.to_data, toHost:@host, port:@port, withTimeout:-1, tag:1 )
  end
end
##### this file belongs in vendor/umberjack_patch/log_message.m


#import "../Pods/CocoaLumberjack/Lumberjack/DDLog.h"

@interface DDLogMessage (InstVar)

- (NSString*) logMsg;
- (NSNumber *) logLevel;

@end

@implementation DDLogMessage (InstVar)

- (NSString *)logMsg {
    return logMsg;
}

-(NSNumber *) logLevel {
    return [NSNumber numberWithInt:logLevel];

}
@end
Log = Motion::Log

class AppDelegate

  def application(application, didFinishLaunchingWithOptions:launchOptions)
    .....
    Log.addLogger(DDASLLogger.sharedInstance())
    Log.addLogger(DDTTYLogger.sharedInstance())

    papertrail_logger =  PapertrailLogger.sharedInstance('logs.papertrailapp.com', YOUR_PORT)
    Log.addLogger(papertrail_logger)
    Log.level = ENV["log_level"].to_sym
    ....

  end

end
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'

require 'bundler'
Bundler.require

Motion::Project::App.setup do |app|
  app.pods do
    pod 'CocoaLumberjack'
    pod 'CocoaAsyncSocket' 
  end
  app.vendor_project 'vendor/lumberjack_patch', :static

end
source :rubygems
gem "rake"
gem 'motion-logger' #cocoalumberjack wrapper