Last active
May 12, 2018 21:54
-
-
Save iwarshak/5773987 to your computer and use it in GitHub Desktop.
Here is what you need to get your Rubymotion application logs sent to papertrailapp.com. I am using Cocoalumberjack (CLJ) which seems to be the logging framework of choice for Cocoa, motion-logger which is a thin RM wrapper around Cocoalumberjack. CLJ allows you to write your own loggers, which is what PapertrailLogger is. It simply fires off lo…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
gem "rake" | |
gem 'motion-logger' #cocoalumberjack wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would not use this in production. I noticed very strange phone behavior when this was installed on my app (and logging was happening in the background).