Permalink
Browse files

init commit

  • Loading branch information...
0 parents commit 7bd8e552f527ecdab022d972e0b4a192dbcbf1d0 @siuying committed May 31, 2012
Showing with 5,924 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +13 −0 Rakefile
  3. +5 −0 app/app_delegate.rb
  4. +83 −0 lib/logger/log.rb
  5. +13 −0 lib/motion-logger.rb
  6. +39 −0 spec/log_spec.rb
  7. +6 −0 vendor/Podfile.lock
  8. +24 −0 vendor/Pods/CocoaLumberjack/.gitignore
  9. +6 −0 vendor/Pods/CocoaLumberjack/.hgignore
  10. +18 −0 vendor/Pods/CocoaLumberjack/CocoaLumberjack.podspec
  11. +18 −0 vendor/Pods/CocoaLumberjack/LICENSE.txt
  12. +41 −0 vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h
  13. +99 −0 vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m
  14. +102 −0 vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h
  15. +618 −0 vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m
  16. +334 −0 vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h
  17. +1,346 −0 vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m
  18. +498 −0 vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h
  19. +979 −0 vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m
  20. +49 −0 vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h
  21. +186 −0 vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m
  22. +37 −0 vendor/Pods/CocoaLumberjack/README.markdown
  23. +1 −0 vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h
  24. +1 −0 vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h
  25. +1 −0 vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h
  26. +1 −0 vendor/Pods/Headers/CocoaLumberjack/DDLog.h
  27. +1 −0 vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h
  28. +3 −0 vendor/Pods/Pods-prefix.pch
  29. +15 −0 vendor/Pods/Pods-resources.sh
  30. +462 −0 vendor/Pods/Pods.bridgesupport
  31. +4 −0 vendor/Pods/Pods.xcconfig
  32. +916 −0 vendor/Pods/Pods.xcodeproj/project.pbxproj
  33. BIN vendor/Pods/build-iPhoneSimulator/libPods.a
@@ -0,0 +1,5 @@
+.repl_history
+build
+resources/*.nib
+resources/*.momd
+resources/*.storyboardc
@@ -0,0 +1,13 @@
+$:.unshift("/Library/RubyMotion/lib")
+require 'motion/project'
+require 'rubygems'
+require 'motion-cocoapods'
+require './lib/motion-logger'
+
+Motion::Project::App.setup do |app|
+ app.name = 'logger'
+
+ app.pods do
+ dependency 'CocoaLumberjack'
+ end
+end
@@ -0,0 +1,5 @@
+class AppDelegate
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
+ true
+ end
+end
@@ -0,0 +1,83 @@
+module LoggerClassMethods
+ FLAGS = {
+ :error => (1<<0), # 0...0001
+ :warn => (1<<1), # 0...0010
+ :info => (1<<2), # 0...0100
+ :verbose => (1<<3), # 0...1000
+ :debug => (1<<3) # 0...1000
+ }
+
+ LEVELS = {
+ :off => 0,
+ :error => FLAGS[:error],
+ :warn => FLAGS[:error] | FLAGS[:warn],
+ :info => FLAGS[:error] | FLAGS[:warn] | FLAGS[:info],
+ :verbose => FLAGS[:error] | FLAGS[:warn] | FLAGS[:info] | FLAGS[:verbose],
+ :debug => FLAGS[:error] | FLAGS[:warn] | FLAGS[:info] | FLAGS[:verbose]
+ }
+
+ def level=(level)
+ @level = level
+ end
+
+ def level
+ @level
+ end
+
+ def async=(async)
+ @async = async
+ end
+
+ def async
+ @async
+ end
+
+ def error(message)
+ __log(:error, message)
+ end
+
+ def warn(message)
+ __log(:warn, message)
+ end
+
+ def info(message)
+ __log(:info, message)
+ end
+
+ def debug(message)
+ __log(:verbose, message)
+ end
+ alias_method :verbose, :debug
+
+ def logging?(flag)
+ (LEVELS[level] & FLAGS[flag]) > 0
+ end
+
+ protected
+ def __log(flag, message)
+ return unless logging?(flag)
+ raise ArgumentError, "flag must be one of #{FLAGS.keys}" unless FLAGS.keys.include?(flag)
+ async_enabled = self.async || (self.level == :error)
+
+ log(async_enabled,
+ level:LEVELS[level],
+ flag:FLAGS[flag],
+ context:0,
+ file:__FILE__,
+ function:__method__,
+ line:__LINE__,
+ tag:0,
+ format:message)
+ end
+end
+
+class Log < DDLog
+ class << self
+ alias_method :flush, :flushLog
+ end
+
+ extend LoggerClassMethods
+
+ @async = true
+ @level = :info
+end
@@ -0,0 +1,13 @@
+unless defined?(Motion::Project::Config)
+ raise "This file must be required within a RubyMotion project Rakefile."
+end
+
+Motion::Project::App.setup do |app|
+ Dir.glob(File.join(File.dirname(__FILE__), 'logger/*.rb')).each do |file|
+ app.files.unshift file
+ end
+
+ app.pods do
+ dependency 'CocoaLumberjack'
+ end
+end
@@ -0,0 +1,39 @@
+describe "Log" do
+ before do
+ @file_logger = DDFileLogger.alloc.init
+ @file_logger.rollingFrequency = 60 * 60 * 24
+ @file_logger.logFileManager.maximumNumberOfLogFiles = 1
+ Log.addLogger(@file_logger)
+ end
+
+ after do
+ Log.flush
+ @file_logger.logFileManager.unsortedLogFilePaths.each do |file|
+ File.delete(file)
+ end
+ Log.removeAllLoggers
+ end
+
+ describe "FileLogger" do
+ it "should log with specific levels" do
+ Log.level = :warn
+
+ Log.info "Hello World"
+ Log.warn "WARNING!"
+
+ Log.level = :info
+ Log.info "Foo"
+ Log.debug "Lah"
+ Log.flush
+
+ file = @file_logger.logFileManager.sortedLogFilePaths.first
+ logs = open(file).read
+ logs.should.not.be.nil
+ logs.should.not.include "Hello World"
+ logs.should.include "WARNING!"
+ logs.should.include "Foo"
+ logs.should.not.include "Lah"
+ end
+ end
+
+end
@@ -0,0 +1,6 @@
+PODS:
+ - CocoaLumberjack (1.3.3)
+
+DEPENDENCIES:
+ - CocoaLumberjack
+ - CocoaLumberjack
@@ -0,0 +1,24 @@
+# Xcode
+build/*
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+*.xcworkspace
+!default.xcworkspace
+xcuserdata
+profile
+*.moved-aside
+.DS_Store?
+Icon?
+
+# Thumbnails
+._*
+
+# Files that might appear on external disk
+.Spotlight-V100
+.Trashes
@@ -0,0 +1,6 @@
+syntax: glob
+
+Xcode/*/build
+*.pbxuser
+*.mode1v3
+*.xcuserdatad
@@ -0,0 +1,18 @@
+Pod::Spec.new do |s|
+ s.name = 'CocoaLumberjack'
+ s.version = '1.3.1'
+ s.license = 'BSD'
+ s.summary = 'A fast & simple, yet powerful & flexible logging framework for Mac and iOS.'
+ s.homepage = 'https://github.com/robbiehanson/CocoaLumberjack'
+ s.author = { 'Robbie Hanson' => 'robbiehanson@deusty.com' }
+ s.source = { :git => 'https://github.com/robbiehanson/CocoaLumberjack.git',
+ :tag => '1.3.1' }
+
+ s.description = 'It is similar in concept to other popular logging frameworks such as log4j, ' \
+ 'yet is designed specifically for objective-c, and takes advantage of features ' \
+ 'such as multi-threading, grand central dispatch (if available), lockless ' \
+ 'atomic operations, and the dynamic nature of the objective-c runtime.'
+
+ s.source_files = 'Lumberjack'
+ s.clean_paths = 'Benchmarking', 'Xcode'
+end
@@ -0,0 +1,18 @@
+Software License Agreement (BSD License)
+
+Copyright (c) 2010, Deusty, LLC
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms,
+with or without modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+* Neither the name of Deusty nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of Deusty, LLC.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,41 @@
+#import <Foundation/Foundation.h>
+#import <asl.h>
+
+#import "DDLog.h"
+
+/**
+ * Welcome to Cocoa Lumberjack!
+ *
+ * The project page has a wealth of documentation if you have any questions.
+ * https://github.com/robbiehanson/CocoaLumberjack
+ *
+ * If you're new to the project you may wish to read the "Getting Started" wiki.
+ * https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
+ *
+ *
+ * This class provides a logger for the Apple System Log facility.
+ *
+ * As described in the "Getting Started" page,
+ * the traditional NSLog() function directs it's output to two places:
+ *
+ * - Apple System Log
+ * - StdErr (if stderr is a TTY) so log statements show up in Xcode console
+ *
+ * To duplicate NSLog() functionality you can simply add this logger and a tty logger.
+ * However, if you instead choose to use file logging (for faster performance),
+ * you may choose to use a file logger and a tty logger.
+**/
+
+@interface DDASLLogger : DDAbstractLogger <DDLogger>
+{
+ aslclient client;
+}
+
++ (DDASLLogger *)sharedInstance;
+
+// Inherited from DDAbstractLogger
+
+// - (id <DDLogFormatter>)logFormatter;
+// - (void)setLogFormatter:(id <DDLogFormatter>)formatter;
+
+@end
@@ -0,0 +1,99 @@
+#import "DDASLLogger.h"
+
+#import <libkern/OSAtomic.h>
+
+/**
+ * Welcome to Cocoa Lumberjack!
+ *
+ * The project page has a wealth of documentation if you have any questions.
+ * https://github.com/robbiehanson/CocoaLumberjack
+ *
+ * If you're new to the project you may wish to read the "Getting Started" wiki.
+ * https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
+**/
+
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
+
+
+@implementation DDASLLogger
+
+static DDASLLogger *sharedInstance;
+
+/**
+ * The runtime sends initialize to each class in a program exactly one time just before the class,
+ * or any class that inherits from it, is sent its first message from within the program. (Thus the
+ * method may never be invoked if the class is not used.) The runtime sends the initialize message to
+ * classes in a thread-safe manner. Superclasses receive this message before their subclasses.
+ *
+ * This method may also be called directly (assumably by accident), hence the safety mechanism.
+**/
++ (void)initialize
+{
+ static BOOL initialized = NO;
+ if (!initialized)
+ {
+ initialized = YES;
+
+ sharedInstance = [[DDASLLogger alloc] init];
+ }
+}
+
++ (DDASLLogger *)sharedInstance
+{
+ return sharedInstance;
+}
+
+- (id)init
+{
+ if (sharedInstance != nil)
+ {
+ return nil;
+ }
+
+ if ((self = [super init]))
+ {
+ // A default asl client is provided for the main thread,
+ // but background threads need to create their own client.
+
+ client = asl_open(NULL, "com.apple.console", 0);
+ }
+ return self;
+}
+
+- (void)logMessage:(DDLogMessage *)logMessage
+{
+ NSString *logMsg = logMessage->logMsg;
+
+ if (formatter)
+ {
+ logMsg = [formatter formatLogMessage:logMessage];
+ }
+
+ if (logMsg)
+ {
+ const char *msg = [logMsg UTF8String];
+
+ int aslLogLevel;
+ switch (logMessage->logLevel)
+ {
+ // Note: By default ASL will filter anything above level 5 (Notice).
+ // So our mappings shouldn't go above that level.
+
+ case 1 : aslLogLevel = ASL_LEVEL_CRIT; break;
+ case 2 : aslLogLevel = ASL_LEVEL_ERR; break;
+ case 3 : aslLogLevel = ASL_LEVEL_WARNING; break;
+ default : aslLogLevel = ASL_LEVEL_NOTICE; break;
+ }
+
+ asl_log(client, NULL, aslLogLevel, "%s", msg);
+ }
+}
+
+- (NSString *)loggerName
+{
+ return @"cocoa.lumberjack.aslLogger";
+}
+
+@end
Oops, something went wrong.

0 comments on commit 7bd8e55

Please sign in to comment.