Created
February 17, 2015 03:06
-
-
Save PaulDMendoza/2b8cdf853f7e0c94633f to your computer and use it in GitHub Desktop.
Loggly Simple Swift Logger (requires Alamofire ONLY!!!!)
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
// | |
// Loggly.swift | |
// mobile | |
// | |
// Created by Paul Mendoza | |
// Twitter: PaulDMendoza | |
// | |
import Foundation | |
import UIKit | |
class Loggly { | |
class func Log(message : Dictionary<NSString, AnyObject>) { | |
Loggly.Log(message, level: "INFO") | |
} | |
class func Log(message : Dictionary<NSString, AnyObject>, level : String) { | |
print("Log - ") | |
println(message) | |
var version = UIDevice.currentDevice().systemVersion | |
var model = UIDevice.currentDevice().model | |
let dateFormatter = NSDateFormatter() | |
dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC") | |
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" | |
let timestamp = dateFormatter.stringFromDate(NSDate()) | |
var manager = Manager.sharedInstance | |
//Passing all the headers you want! | |
manager.session.configuration.HTTPAdditionalHeaders = [ | |
"Content-Type": "application/json" | |
] | |
request(.POST, "https://logs-01.loggly.com/inputs/[LOGGLYKEY]/tag/iphone/", parameters: [ "object" : message, "timestamp": timestamp, "level": level, "version": version, "model" : model, "process": "iphone" ], | |
encoding: .JSON) | |
.response { (_, _, _, error) in | |
if error != nil { | |
println(error) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment