working on it ...

Filters

Explore Public Snippets

Sort by

Found 65 snippets matching: nslog

    public by marksimon232  283249  0  7  1

    Swift 2: Custom logger that mimics NSLog

    Using this initializer, you can easily build a custom logger that mimics NSLog:
    public func SWLog(format: String, _ args: CVarArgType...) {
        let dateFormatter = NSDateFormatter()
        dateFormatter.dateFormat = 
            NSDateFormatter.dateFormatFromTemplate(
                "mm:ss:SSS", options: 0, 
                locale: NSLocale.currentLocale())
        let timeString = 
            dateFormatter.stringFromDate(NSDate())
        print("\(timeString): " + 
            String(format: format, arguments: args))
    }

    public by marksimon232  4523  2  6  1

    Swift 2: Creating the date Formatter

    internal func BuildSimpleTimeFormatter() -> NSDateFormatter {
        let dateFormatter = NSDateFormatter()
        dateFormatter.dateFormat = NSDateFormatter.dateFormatFromTemplate("mm:ss:SSS", options: 0, locale: NSLocale.currentLocale())
        return dateFormatter
    }
    
    internal let dateFormatter = BuildSimpleTimeFormatter()
    
    public func SWLog(format: String, _ args: CVarArgType...) {
        #if DEBUG
            let timeString = dateFormatter.stringFromDate(NSDate())
            print("\(timeString): " + String(format: format, arguments: args), &errStream)
        #endif
    }

    public by marksimon232  2963  0  7  1

    Swift: Revisiting printing with string formats

    You pass NSLog a format string followed by a variadic list of Objective-C-compatible parameters. 
    The parameters map to specifiers embedded within the format string.
    
    NSLog("Dictionary: %@, Double: %0.2f", ["Hello":3], 2.7)            

    external by warriorg  235864  0  3  0

    My aLog and dLog macros in Swift (to abbreviate NSLog)

    My aLog and dLog macros in Swift (to abbreviate NSLog): Macros.swift
    //
    //  Macros.swift
    //
    //  Created by Xavier Muñiz on 6/12/14.
    
    import Foundation
    
    
    // dLog and aLog macros to abbreviate NSLog.
    // Use like this:
    //
    //   dLog("Log this!")
    //
    #if DEBUG
        func dLog(message: String, filename: String = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) {
            NSLog("[\(filename.lastPathComponent):\(line)] \(function) - \(message)")
        }
    #else
        func dLog(message: String, filename: String = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) {
        }
    #endif
    func aLog(message: String, filename: String = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) {
        NSLog("[\(filename.lastPathComponent):\(line)] \(function) - \(message)")
    }
    
    
    

    external by Bishal Ghimire  251  0  3  0

    Debug only Logger for Swift using NSLog

    Debug only Logger for Swift using NSLog: gistfile1.txt
    import Foundation
    
    #if DEBUG
        func dLog(@autoclosure message:  () -> String, filename: NSString = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) {
            NSLog("[\(filename.lastPathComponent):\(line)] \(function) - %@", message())
        }
    #else
        func dLog(@autoclosure message:  () -> String, filename: NSString = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) {
        }
    #endif
    func aLog(message: String, filename: NSString = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) {
        NSLog("[\(filename.lastPathComponent):\(line)] \(function) - %@", message)
    }
    
    
    

    external by AndreyZarembo  57  0  1  0

    NSLog analog for C

    NSLog analog for C: VSLog.c
    C
    // Also include this
    // #include <stdio.h>
    // #include <time.h>
    // #include <string.h>
    #define VSLog(fmt, ...) {\
      time_t timer;\
      time(&timer);\
      char *timestamp = ctime(&timer);\
      timestamp[strlen(timestamp)-2] = '\0';\
      printf("%s: %s " fmt "\n", timestamp,  __PRETTY_FUNCTION__,##__VA_ARGS__);\
    }
    
    

    external by jun66j5  2895  7  3  0

    Redirect stdout/stderr to NSLog on iOS Simulator

    Redirect stdout/stderr to NSLog on iOS Simulator: main.m
    #include <unistd.h>
    
    static int redirect_nslog(const char *prefix, const char *buffer, int size)
    {
        NSLog(@"%s (%d bytes): %.*s", prefix, size, size, buffer);
        return size;
    }
    
    static int stderr_redirect_nslog(void *inFD, const char *buffer, int size)
    {
        return redirect_nslog("stderr", buffer, size);
    }
    
    static int stdout_redirect_nslog(void *inFD, const char *buffer, int size)
    {
        return redirect_nslog("stdout", buffer, size);
    }
    
    int main(int argc, char *argv[])
    {
        stdout->_write = stdout_redirect_nslog;
        stderr->_write = stderr_redirect_nslog;
        /* ... */
    }
    
    

    external by Scott Ng Sze Kiat  34  0  1  0

    Exclude NSLog statements in Release builds

    Exclude NSLog statements in Release builds: Exclude NSLog
    #ifndef DEBUG
    #define NSLog(...);
    #endif
    
    

    external by rraallvv  11  0  1  0

    NSLog w/o timestamp nor cached output

    NSLog w/o timestamp nor cached output: NSLog
    #define NSLog(FORMAT, ...) fprintf( stderr, "%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
    
    

    external by Tomohisa Takaoka  11  0  1  0

    Disable NSLog for keyboard extension

    Disable NSLog for keyboard extension: App.pch
    #ifdef DEBUG
    //#  define LOG(...) NSLog(@"%@", __VA_ARGS__)
    //#  define LOG_METHOD NSLog(@"%s", __func__)
    //#  define LOG_FORMAT(...) NSLog(__VA_ARGS__)
    #  define LOG(...) ;
    #  define LOG_METHOD ;
    #  define LOG_FORMAT(...) ;
    #else
    #  define LOG(...) ;
    #  define LOG_METHOD ;
    #  define LOG_FORMAT(...) ;
    #endif
    
    
    
    • Public Snippets
    • Channels Snippets