Latest 0.1.4
Homepage https://github.com/mateuszmackowiak/MMLogger
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

MMLogger is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "MMLogger"

Usage

Basic usage:

import MMLogger

MMLogger.default.warning("warning")

Log Levels

public enum MMLogLevel : UInt {
    case off
    case error
    case warning
    case info
    case debug
    case verbose
}

Create a wrapper for simple ussage

public var log: MMLogger {
    return MMLogger.default
}

log.warning("warning")

By default an instance of MMPrintLogger.default is registered for log level .verbose
To remove default logger use MMLogger.default.removeAllLoggers()

Adding default logger for custom log level:

// or log.addLogger(logger: MMPrintLogger(), for: .debug) 
MMLogger.default.addLogger(logger: MMPrintLogger.default, for: .debug)

Adding a custom Logger


class MYCustomLogger: NSObject, MMLoggerProtocol {

    func log(message: MMLogMessage) {
        print("(message.message)n")
    }
}

// or log.addLogger(logger: MYCustomLogger(), for: .warning) 
MMLogger.default.addLogger(logger: MYCustomLogger(), for: .warning)

Adding a custom Formatter

class MyLoggerFormatter: NSObject, MMLoggerFormatter {
    func format(_ message: MMLogMessage) -> String {
        return "++++++++++n(message.date) [(message.level)] (message.message)n"
    }
}

let logger = MMPrintLogger()
logger.formatter = MyLoggerFormatter()
// or log.addLogger(logger: logger, for: .verbose) 
MMLogger.default.addLogger(logger: logger, for: .verbose)

Add Logstash logger


let logstashLogger = MMLogstashLogger(host: "localhost", port: 9601, timeout: 5, logActivity: true)
log.addLogger(logstashLogger, from: .verbose)

Setup Logstash / Kibana / Elasticsearch server

Install components

brew install elasticsearch
brew services start elasticsearch

brew install kibana
brew services start kibana

brew install logstash

Use logstash-config.conf to configure logstash

LaunchAgents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.bcd.logstash</string>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>~/Documents/logstash.log</string>
<key>StandardErrorPath</key>
<string>~/Documents/logstash.log</string>
<key>ProgramArguments</key> 
<array>
<string>/usr/local/bin/logstash</string>
<string>-f</string>
<string>~/Documents/logstash-config.conf</string>
</array>
<key>RunAtLoad</key>
<true/> 
</dict>
</plist>

Author

Mateusz Mackowiak, [email protected]

License

MMLogger is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "MMLogger",
    "version": "0.1.4",
    "summary": "MMLogger is a wrapper for loggers",
    "homepage": "https://github.com/mateuszmackowiak/MMLogger",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Mateusz Mackowiak": "[email protected]"
    },
    "source": {
        "git": "https://github.com/mateuszmackowiak/MMLogger.git",
        "tag": "0.1.4"
    },
    "platforms": {
        "ios": "8.0"
    },
    "pushed_with_swift_version": "3.0",
    "subspecs": [
        {
            "name": "Core",
            "source_files": "MMLogger/Classes/Core/*.swift"
        },
        {
            "name": "Logstash",
            "source_files": "MMLogger/Classes/Logstash/*.swift",
            "dependencies": {
                "CocoaAsyncSocket": [],
                "MMLogger/Core": []
            }
        }
    ]
}

Pin It on Pinterest

Share This