0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Logの送信をやさしくしてくれるPuree

Last updated at Posted at 2023-02-10

Logの送信をやさしくしてくれるPuree

  • logを収集するもので下記の機能をもつオープンソース。
    • filter: ログに共通パラメーターを追加する
    • buffer: バッファに入れる
    • patch: 複数のログを1つにまとめて送る
  • 現在はPuree-Swiftに移行されている模様。
  • githubページ

overview.png

インストール方法

pod "Puree"

使い方

  1. filter, outputなどの動きを定義するクラスを作る

    class ActivityFilter: PURFilter {
        override func logs(object: Any, tag: String, captured: String?) -> [PURLog] {
           let currentDate = logger.currentDate()
            return [PURLog(tag: "activity.tap", date: currentDate, userInfo: ["an event": object])] 
        }
    }
    
    class ConsoleOutput: PUROutput {
     override func emit(log: PURLog) {
         // ここにLogを送るロジックを描く
        }
    }
    
  2. configurationを生成してfilter, outputなどの設定を行う。loggerを生成する

    let configuration = PURLoggerConfiguration.default()
    configuration.filterSettings = [
        PURFilterSetting(filter: ActivityFilter.self, tagPattern: "activity.**"),
        // filter settings ...
    ]
    configuration.outputSettings = [
        PUROutputSetting(output: ConsoleOutput.self,   tagPattern: "activity.**"),
        PUROutputSetting(output: ConsoleOutput.self,   tagPattern: "pv.**"),
        PUROutputSetting(output: LogServerOutput.self, tagPattern: "pv.**", settings:[PURBufferedOutputSettingsFlushIntervalKey: 10]),
        // output settings ...
    ]
    
    let logger = PURLogger(configuration: configuration)
    
  3. postメソッドを使ってログを送信する

    logger.post(["recipe_id": "123"], tag: "pv.recipe_detail")
    
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?