Giter VIP home page Giter VIP logo

sematext-logsene-ios's Introduction

SDK for Shipping iOS Application Logs to Sematext

CI Status Version License Platform

Sematext Logs is ELK as a Service. This library lets you collect mobile analytics and log data from your iOS and WatchOS applications using Sematext. There is an equivalent library for shipping logs from Android available. If you don't have a Sematext account, you can register for free to get your App token.

Use the Mobile Application Logs Integration to get out-of-the-box reports with the most important information about your mobile applications.

Get an overview of your mobile apps with information like:

  • top iOS and WatchOS versions
  • top log severity and version names

Mobile Logpack Overview

Explore the common errors associated with your mobile applications and see an aggregated error view including:

  • number of errors and theirs count over time
  • top operating systems, top iOS and WatchOS versions that are reporting errors
  • error log events

Mobile Logpack Errors

Get insights from dedicated iOS / WatchOS reports that include:

  • mobile operating system logs count histogram and their count
  • top severity, versions, version codes, and version names
  • mobile applications log events

Mobile Logpack iOS

Getting Started

  1. Logsene log shipping library for iOS and WatchOS is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Logsene"
  1. Run pod install
  2. Call LogseneInit() from your application delegate in didFinishLaunchingWithOptions:. For example:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        try! LogseneInit("<yourtoken>", type: "example")
    }
}

Additional options are available:

  • the receiverUrl parameter allows specifying the data reciver if you are using our EU location or Sematext Enterprise
  • the automaticLocationEnriching parameter enabled automatic enrichment of logs from the mobile application with location data
  • offline storage size can be configured by using the maxOfflineFileSize (100000 by default) and maxOfflineFiles (10 by default) parameters. The size of the offline storage will be equal to maxOfflineFileSize multiplied by maxOfflineFiles.

Note: We highly recommend creating a write-only token in your application settings for use in your mobile apps.

Example Application

You can try out the example application with Cocoapods:

cd ~/Desktop
pod try Logsene

Make sure to set your own application token in AppDelegate.swift.

Mobile Application Analytics

You can collect application analytics using Sematext. To do that, use the LLogEvent() function to send custom events. For example, you might want to send an event each time the user completes a game level:

LLogEvent(["event": "level_completed", "message": "Level 3 completed", "value": "3"])

To visualize the collected data, you would use the integrated Kibana dashboard.

If you don't see the events in the dashboard immediately, note that this library sends data in batches to preserve the battery (every 60s), or if there are more than 10 messages queued up. Messages are saved while the device is offline, so you don't have to worry about losing any data.

When it comes to the structure of your events, you are free to choose your own, the above is just an example. You can use any number of fields, and you can use nested fields. Basically, any valid JSON object will work fine. Note that the library reserves the meta field for meta information (see below). If you set a value for this field when sending an event, no meta information will be included for that event.

Meta Fields

A few predefined meta fields are included in each event sent to Sematext. The fields are stored inside the "meta" field.

  • versionName (app version string, eg. 1.0)
  • versionCode (app build number, eg. 92)
  • osRelease (iOS or WatchOS version, eg. 9.3.0)
  • uuid (device identifier)
  • OS type (iOS or WatchOS)

You can set your own meta fields with LogseneSetDefaultMeta. For example:

LogseneSetDefaultMeta(["user": "[email protected]", "plan": "free"])

Note that these meta fields are global, and will be attached to every event sent to Logsene.

Pausing & Resuming Logs Sending

The library can be instructed to stop sending logs on demand. To do that you need to call the following function:

LogsenePauseSendingLogs()

Logs sending can be resumed by calling the following function:

LogseneResumeSendingLogs()

Note that the logs that are in the buffer and were waiting to be sent at the time of pausing will not be sent until the logs sending process is resumed.

Centralized Logging

The library offers some basic functions for centralized logging:

  • LLogDebug
  • LLogInfo
  • LLogWarn
  • LLogError

Each function provides two variants - logging a message or error without and with the device location.

Example of writing a log message:

DDLogInfo("hello world!")

Example of writing a log message with location data:

let location = LogsLocation(fromLatitude: 53.13, fromLongitude: 23.16)
LLogInfo(withMessage: "hello world with location!", withLocation: location)

Automatically enrich logs with location data on iOS and WatchOS

If you would like to allow the library to automatically enrich log data with the location data it is as easy as properly initializing the library, for example:

LogseneInit("<yourtoken>", type: "example", automaticLocationEnriching: true, useLocationOnlyInForeground: true)

There are two properties here:

  • automaticLocationEnriching - when set to true the library will try to enrich the logs with location information,
  • useLocationOnlyInForeground - when set to true the location will only be gathered when the application is in forground.

In addition to setting up the LogseneInit properly you also need to ensure to include two additonal string values in the Info.plist file that will be diplayed when asking the user to allow location data to be gathered. Those aree:

  • Privacy - Location Always and When In Use Usage Description
  • Privacy - Location When In Use Usage Description

Automatic location enriching only works with iOS and WatchOS, not MacOS.

For integrating with existing logging frameworks, see below.

CocoaLumberjack

If you're using CocoaLumberjack for logging, you can use the custom Logsene logger to send log messages to Sematext automatically. You should configure CocoaLumberjack to use the Logsene logger:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // NOTE: Set your token below
        try! LogseneInit("<yourtoken>", type: "example")

        // Here we setup CocoaLumberjack to log to both XCode console and Logsene
        DDLog.addLogger(DDTTYLogger.sharedInstance())
        DDLog.addLogger(LogseneLogger())
        DDLogInfo("hello world from CocoaLumberjack!")
        return true
    }
}

LogseneLogger is not included in the pod, but you can find the implementation here. Feel free to use it in your own project.

How to log unhandled exceptions

You can log any unhandled Foundation exceptions by defining your own uncaught exception handler. For example:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // NOTE: Set your token below
        try! LogseneInit("<yourtoken>", type: "example")

        NSSetUncaughtExceptionHandler { exception in
            // log unhandled exception message
            LLogError(exception)
        }
        return true
    }
}

sematext-logsene-ios's People

Contributors

aebischers avatar amir-hadzic avatar gr0 avatar otisg avatar ssuvalija avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sematext-logsene-ios's Issues

Disable verbose console logging?

The new release is working great, with one small annoyance: In Xcode, the console is full of logs like:

2020-12-06 14:15:12.864514-0800 APP[5819:157279] Opening new logs file
2020-12-06 14:15:12.865915-0800 APP[5819:157279] Starting log files directory cleanup
2020-12-06 14:15:12.866494-0800 APP[5819:157279] Deleting file sematext_logs_sdk_1607292852.863614
2020-12-06 14:16:12.864751-0800 APP[5819:157814] Rolling file
2020-12-06 14:16:12.865142-0800 APP[5819:157814] Opening new logs file
2020-12-06 14:16:12.866461-0800 APP[5819:157814] Starting log files directory cleanup
2020-12-06 14:16:12.867291-0800 APP[5819:157814] Deleting file sematext_logs_sdk_1605713011.9342098
2020-12-06 14:17:12.865333-0800 APP[5819:158437] Rolling file
2020-12-06 14:17:12.865710-0800 APP[5819:158437] Opening new logs file
2020-12-06 14:17:12.867074-0800 APP[5819:158437] Starting log files directory cleanup
2020-12-06 14:17:12.867827-0800 APP[5819:158437] Deleting file sematext_logs_sdk_1605711811.9245071
2020-12-06 14:18:12.866024-0800 APP[5819:159970] Rolling file
2020-12-06 14:18:12.866502-0800 APP[5819:159970] Opening new logs file
2020-12-06 14:18:12.869136-0800 APP[5819:159970] Starting log files directory cleanup
2020-12-06 14:18:12.870095-0800 APP[5819:159970] Deleting file sematext_logs_sdk_1607292972.8654451

Please disable the console logs or at least provide a verbosity setting. Thanks!

SQLite.swift dependency has hard-coded path

This is a known wontfix issue: stephencelis/SQLite.swift#425

The hard-coded path causes compilation problems such as duplicate modulemap files (if you have Xcode.app in your path, and missing files if you don't. (Assuming you're using something other than Xcode.app, which many devs would be.)

[UPDATED] Xcode 11.4.1, Swift 5.2

Swift 4 version of the pod

Hello is there any plan to release the swift 4 version of this repo. The current repo does not work with xCode 9

Swift 4 migration

There is a dependency listed in the .podspec file: s.dependency 'SQLite.swift', '~> 0.10.1'.
However, the version listed only supports Swift 3, as a result, the project can't be built with Xcode 11.
Are you planning to migrate this repo to a newer Swift version?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.