<commit_before>Puree
========

[![Version](https://img.shields.io/cocoapods/v/Puree.svg?style=flat)](http://cocoadocs.org/docsets/Puree)
[![License](https://img.shields.io/cocoapods/l/Puree.svg?style=flat)](http://cocoadocs.org/docsets/Puree)
[![Platform](https://img.shields.io/cocoapods/p/Puree.svg?style=flat)](http://cocoadocs.org/docsets/Puree)

## Description

Puree is a log collector which provides some features like below

- Filtering: Enable to interrupt process before sending log. You can add common params to logs, or the sampling of logs.
- Buffering: Store logs to buffer until log was sent.
- Batching: Enable to send logs by 1 request.
- Retrying: Retry to send logs after backoff time automatically if sending logs fails.

![](./images/overview.png)

Puree helps you unify your logging infrastructure.

## Usage

### Configure Logger

```swift
// Swift

let configuration = PURLoggerConfiguration.defaultConfiguration()
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 ...
]

logger = PURLogger(configuration: configuration)
```

```objective-c
// Objective-C

PURLoggerConfiguration *configuration = [PURLoggerConfiguration defaultConfiguration];
configuration.filterSettings = @[
    [[PURFilterSetting alloc] initWithFilter:[ActivityFilter class]
                                  tagPattern:@"activity.**"],
    // filter settings ...
];
configuration.outputSettings = @[
    [[PUROutputSetting alloc] initWithOutput:[ConsoleOutput class]
                                  tagPattern:@"activity.**"],
    [[PUROutputSetting alloc] initWithOutput:[ConsoleOutput class]
                                  tagPattern:@"pv.**"],
    [[PUROutputSetting alloc] initWithOutput:[LogServerOutput class]
                                  tagPattern:@"pv.**"
                                  settings:@{PURBufferedOutputSettingsFlushIntervalKey: @10}],
    // output settings ...
];

PURLogger *logger = [[PURLogger alloc] initWithConfiguration:configuration];
```

Expected result

```
tag name                 [ Filter Plugin ]  -> [ Output Plugin ]
-----------------------------------------------------------------
activity.recipe.view  -> [ ActivityFilter ] -> [ ConsoleOutput ]
activity.bargain.view -> [ ActivityFilter ] -> [ ConsoleOutput ]
pv.recipe_detail      -> ( no filter )      -> [ ConsoleOutput ], [ LogServerOutput(FlushInterval:10sec) ]
event.special         -> ( no filter )      -> ( no output )
```

### Post log

Post log object(anyObject) in an arbitrary timing.

```swift
// Swift

logger.postLog(["recipe_id": "123"], tag: "pv.recipe_detail")
```

```objective-c
// Objective-C

[logger postLog:@[@"recipe_id": @"123"] tag: @"pv.recipe_detail"]
```

### Plugins

You can create plugins. See [Create Plugins](https://github.com/cookpad/puree-ios/wiki/Create-plugins)

## Tag system

### Tag

Tag is consisted of multiple term split by `.`.
For example `activity.recipe.view`, `pv.recipe_detail`.
You can specify tag to log freely.<commit_msg>Fix objc hash syntax in README<commit_after>Puree
========

[![Version](https://img.shields.io/cocoapods/v/Puree.svg?style=flat)](http://cocoadocs.org/docsets/Puree)
[![License](https://img.shields.io/cocoapods/l/Puree.svg?style=flat)](http://cocoadocs.org/docsets/Puree)
[![Platform](https://img.shields.io/cocoapods/p/Puree.svg?style=flat)](http://cocoadocs.org/docsets/Puree)

## Description

Puree is a log collector which provides some features like below

- Filtering: Enable to interrupt process before sending log. You can add common params to logs, or the sampling of logs.
- Buffering: Store logs to buffer until log was sent.
- Batching: Enable to send logs by 1 request.
- Retrying: Retry to send logs after backoff time automatically if sending logs fails.

![](./images/overview.png)

Puree helps you unify your logging infrastructure.

## Usage

### Configure Logger

```swift
// Swift

let configuration = PURLoggerConfiguration.defaultConfiguration()
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 ...
]

logger = PURLogger(configuration: configuration)
```

```objective-c
// Objective-C

PURLoggerConfiguration *configuration = [PURLoggerConfiguration defaultConfiguration];
configuration.filterSettings = @[
    [[PURFilterSetting alloc] initWithFilter:[ActivityFilter class]
                                  tagPattern:@"activity.**"],
    // filter settings ...
];
configuration.outputSettings = @[
    [[PUROutputSetting alloc] initWithOutput:[ConsoleOutput class]
                                  tagPattern:@"activity.**"],
    [[PUROutputSetting alloc] initWithOutput:[ConsoleOutput class]
                                  tagPattern:@"pv.**"],
    [[PUROutputSetting alloc] initWithOutput:[LogServerOutput class]
                                  tagPattern:@"pv.**"
                                  settings:@{PURBufferedOutputSettingsFlushIntervalKey: @10}],
    // output settings ...
];

PURLogger *logger = [[PURLogger alloc] initWithConfiguration:configuration];
```

Expected result

```
tag name                 [ Filter Plugin ]  -> [ Output Plugin ]
-----------------------------------------------------------------
activity.recipe.view  -> [ ActivityFilter ] -> [ ConsoleOutput ]
activity.bargain.view -> [ ActivityFilter ] -> [ ConsoleOutput ]
pv.recipe_detail      -> ( no filter )      -> [ ConsoleOutput ], [ LogServerOutput(FlushInterval:10sec) ]
event.special         -> ( no filter )      -> ( no output )
```

### Post log

Post log object(anyObject) in an arbitrary timing.

```swift
// Swift

logger.postLog(["recipe_id": "123"], tag: "pv.recipe_detail")
```

```objective-c
// Objective-C

[logger postLog:@{@"recipe_id": @"123"} tag: @"pv.recipe_detail"]
```

### Plugins

You can create plugins. See [Create Plugins](https://github.com/cookpad/puree-ios/wiki/Create-plugins)

## Tag system

### Tag

Tag is consisted of multiple term split by `.`.
For example `activity.recipe.view`, `pv.recipe_detail`.
You can specify tag to log freely.
{'fraction_non_alphanumeric': 0.15600761012732328, 'fraction_numerical': 0.003805063661642031, 'mean_word_length': 3.281954887218045, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4678643', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1887, 'n_words': 452}