Skip to content

Instantly share code, notes, and snippets.

@PaulDMendoza
Created February 17, 2015 03:06
Show Gist options
  • Save PaulDMendoza/2b8cdf853f7e0c94633f to your computer and use it in GitHub Desktop.
Save PaulDMendoza/2b8cdf853f7e0c94633f to your computer and use it in GitHub Desktop.
Loggly Simple Swift Logger (requires Alamofire ONLY!!!!)
//
// 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