• Stars
    star
    480
  • Rank 91,562 (Top 2 %)
  • Language
    Java
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A log collector for Android

Puree Build Status Android Arsenal Release

Description

Puree is a log collector which provides the following features:

  • Filtering: Enable to interrupt process before sending log. You can add common params to logs, or the sampling of logs.
  • Buffering: Store logs to buffers and send them later.
  • Batching: Send logs in a single request with PureeBufferedOutput.
  • Retrying: Retry to send logs after backoff time if sending logs fails.

Puree helps you unify your logging infrastructure.

Installation

This is published on jitpack and you can use Puree as:

// build.gradle
buildscript {
    repositories {
        maven { url 'https://jitpack.io' }
    }
    ...
}

// app/build.gradle
dependencies {
    implementation "com.github.cookpad:puree-android:$latestVersion"
}

Usage

Initialize

Configure Puree with PureeConfiguration in Application#onCreate(), which registers pairs of what and where.

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        Puree.initialize(buildConfiguration(this));
    }

    public static PureeConfiguration buildConfiguration(Context context) {
        PureeFilter addEventTimeFilter = new AddEventTimeFilter();
        return new PureeConfiguration.Builder(context)
                .pureeSerializer(new PureeGsonSerializer())
                .executor(Executors.newScheduledThreadPool(1)) // optional
                .register(ClickLog.class, new OutLogcat())
                .register(ClickLog.class, new OutBufferedLogcat().withFilters(addEventTimeFilter))
                .build();
    }
}

See also: demo/PureeConfigurator.java

Definition of PureeLog objects

Puree requires that clients supply an implementation of PureeSerializer to be able to serialize the logs. For instance, this is an implementation that uses Gson parser:

public class PureeGsonSerializer implements PureeSerializer {
    private Gson gson = new Gson();

    @Override
    public String serialize(Object object) {
        return gson.toJson(object);
    }
}

A log class is just a POJO whose properties are annotated following the requirements of the Json parser that you provided with PureeSerializer.

public class ClickLog {
    @SerializedName("page")
    private String page;
    @SerializedName("label")
    private String label;

    public ClickLog(String page, String label) {
        this.page = page;
        this.label = label;
    }
}

You can use Puree.send() to send these logs to registered output plugins:

Puree.send(new ClickLog("MainActivity", "Hello"));
// => {"page":"MainActivity","label":"Hello"}

Definition of PureeOutput plugins

There are two types of output plugins: non-buffered and buffered.

  • PureeOutput: Non-buffered output plugins write logs immediately.
  • PureeBufferedOutput: Buffered output plugins enqueue logs to a local storage and then flush them in background tasks.

If you don't need buffering, you can use PureeOutput.

public class OutLogcat extends PureeOutput {
    private static final String TYPE = "out_logcat";

    @Override
    public String type() {
        return TYPE;
    }

    @Override
    public OutputConfiguration configure(OutputConfiguration conf) {
        return conf;
    }

    @Override
    public void emit(String jsonLog) {
        Log.d(TYPE, jsonLog);
    }
}

If you need buffering, you can use PureeBufferedOutput.

public class OutFakeApi extends PureeBufferedOutput {
    private static final String TYPE = "out_fake_api";

    private static final FakeApiClient CLIENT = new FakeApiClient();

    @Override
    public String type() {
        return TYPE;
    }

    @Override
    public OutputConfiguration configure(OutputConfiguration conf) {
        // you can change settings of this plugin
        // set interval of sending logs. defaults to 2 * 60 * 1000 (2 minutes).
        conf.setFlushIntervalMillis(1000);
        // set num of logs per request. defaults to 100.
        conf.setLogsPerRequest(10);
        // set retry count. if fail to send logs, logs will be sending at next time. defaults to 5.
        conf.setMaxRetryCount(3);
        return conf;
    }

    @Override
    public void emit(List<String> jsonLogs, final AsyncResult result) {
        // you have to call result.success or result.fail()
        // to notify whether if puree can clear logs from buffer
        CLIENT.sendLog(jsonLogs, new FakeApiClient.Callback() {
            @Override
            public void success() {
                result.success();
            }

            @Override
            public void fail() {
                result.fail();
            }
        });
    }
}

Definition of Filters

If you need to add common params to each logs, you can use PureeFilter:

public class AddEventTimeFilter implements PureeFilter {
    public JsonObject apply(String jsonLog) {
        JsonObject jsonObject = new JsonParser().parse(jsonLog).getAsJsonObject();
        jsonObject.addProperty("event_time", System.currentTimeMillis());
        return jsonOabject.toString();
    }
}

You can make PureeFilter#apply() to return null to skip sending logs:

public class SamplingFilter implements PureeFilter {
    private final float samplingRate;

    public SamplingFilter(float samplingRate) {
        this.samplingRate = samplingRate;
    }

    @Override
    public JsonObject apply(String jsonLog) {
        return (samplingRate < Math.random() ? null : jsonLog);
    }
}

Then register filters to output plugins on initializing Puree.

new PureeConfiguration.Builder(context)
        .register(ClickLog.class, new OutLogcat())
        .register(ClickLog.class, new OutFakeApi().withFilters(addEventTimeFilter, samplingFilter)
        .build();

Purging old logs

To discard unnecessary recorded logs, purge age can be configured in the PureeBufferedOutput subclass.

public class OutPurge extends PureeBufferedOutput {

    // ..

    @Override
    public OutputConfiguration configure(OutputConfiguration conf) {
        // set to purge buffered logs older than 2 weeks
        conf.setPurgeAgeMillis(2 * 7 * 24 * 60 * 60 * 1000);
        return conf;
    }
}

The configured storage must extend EnhancedPureeStorage to support purging of old logs. The default PureeSQLiteStorage can be used to enable this feature.

new PureeConfiguration.Builder(context)
        .storage(new PureeSQLiteStorage(context))
        .register(ClickLog.class, new OutPurge().withFilters(addEventTimeFilter, samplingFilter)
        .build();

Testing

If you want to mock or ignore Puree.send() and Puree.flush(), you can use Puree.setPureeLogger() to replace the internal logger. See PureeTest.java for details.

Release Engineering

  • Update CHANGES.md
  • git tag $latest_version
  • git push origin $latest_version

See Also

Copyright

Copyright (c) 2014 Cookpad Inc. https://github.com/cookpad

See LICENSE.txt for the license.

More Repositories

1

styleguide

Cookpad's coding style guides
1,173
star
2

chanko

Rapidly and safely prototyping your rails application
Ruby
636
star
3

garage

Rails extension for RESTful Hypermedia API
Ruby
511
star
4

kage

Kage (kah-geh) is a shadow proxy server to duplex HTTP requests
Ruby
503
star
5

rrrspec

Distributed RSpec
Ruby
490
star
6

license-tools-plugin

Gradle plugin to check library licenses and generate license pages.
HTML
331
star
7

arproxy

Arproxy is a proxy between ActiveRecord and database adapter
Ruby
326
star
8

kuroko2

Kuroko2 is a web-based job scheduler / workflow engine.
Ruby
313
star
9

expeditor

Expeditor provides asynchronous execution and fault tolerance for Microservices
Ruby
231
star
10

omniauth-rails_csrf_protection

Provides CSRF protection on OmniAuth request endpoint on Rails application.
Ruby
227
star
11

Puree-Swift

🍯 Awesome log aggregator for iOS
Swift
217
star
12

barbeque

Job queue system to run job with Docker
Ruby
196
star
13

LicenseToolsPlugin

Gradle plugin to check library licenses and generate license pages for Android
HTML
174
star
14

grpc_kit

A kit for creating gRPC server/client in Ruby.
Ruby
161
star
15

puree-ios

[Obsoleted] A log collector for iOS (new version! -> https://github.com/cookpad/Puree-Swift)
Objective-C
149
star
16

dmemo

Ruby
130
star
17

dokumi

Automatically check if anything is wrong with the code in a pull request
Ruby
128
star
18

s3ar

A massively fast S3 downloader/uploader
Rust
113
star
19

griffin

gRPC server and client for Ruby
Ruby
102
star
20

android-code-style

Cookpad Android Code Style
Java
89
star
21

elasticfox-ec2tag

Patched Elasticfox (for EC2 Tag) branched from http://aws.amazon.com/developertools/609 and provide standalone version based on http://code.google.com/p/efoxapp/. ELB Tab from hybridfox http://code.google.com/p/hybridfox/
JavaScript
78
star
22

cookpad-pad

Cookpad Pad — A six keys macro pad made by Cookpad.
73
star
23

trice

Provides reference time concept to application. Use it instead of ad-hoc `Time.now`.
Ruby
72
star
24

terraform-aws-eks

A Terraform module to Provision AWS Elastic Kubernetes (EKS) clusters and worker nodes
HCL
70
star
25

global-style-guides

Official style guides for Cookpad Global
66
star
26

issue-reporter-android

Java
61
star
27

cookpad-internship-2015-summer

http://techlife.cookpad.com/entry/2015/09/08/113442
60
star
28

mixed_gauge

A simple and robust database sharding with ActiveRecord.
Ruby
58
star
29

garage_client

Ruby client library for the Garage application API
Ruby
53
star
30

aws-xray

The unofficial AWS X-Ray Tracing SDK for Ruby
Ruby
50
star
31

blouson

Filter tools to mask sensitive log data for rails
Ruby
49
star
32

presentations

The presentations of Cookpad staff
Ruby
48
star
33

deepalert

Serverless SOAR (Security Orchestration, Automation and Response) framework for automatic inspection and evaluation of security alert
Go
44
star
34

pendaxes

Send reminder to developers about their left pending tests!
Ruby
43
star
35

BottomNavWatson

Bottom navigation bar library that allows multiple back stacks and one single navigation graph
Kotlin
40
star
36

cookpad-internship-2016-summer

Docs and materials at Cookpad Internship 2016 Summer
Ruby
39
star
37

react-native-puree

A log collector for React Native
TypeScript
39
star
38

gradle-android-sdk-manager

DEPRECATED
39
star
39

murakumo

Murakumo is the internal DNS server which manages name information using a gossip protocol.
Ruby
38
star
40

RxT4A

DEPRECATED
Java
38
star
41

tokite

Ruby
35
star
42

r53-fox

AWS Route53 GUI client
JavaScript
31
star
43

daifuku

A markdown parser and compiler for log definitions in mobile applications
Ruby
31
star
44

android-crud-paging-v3

Kotlin
30
star
45

kumonos

Moved to https://github.com/cookpad/itacho
Ruby
30
star
46

itacho

itacho to manage and operate envoy based service mesh.
Go
28
star
47

gem_collector

Collect gems used by applications
Ruby
27
star
48

iam-fox

AWS IAM GUI client
JavaScript
26
star
49

sds

Envoy's v1 Service Discovery Service API and v2 Endpoint Discovery Service API
Rust
24
star
50

ViewsWaiter

A reactive approach for updating views that you don't view
Kotlin
23
star
51

streamy

Basic toolset for hooking into event stream
Ruby
22
star
52

cpc1.0

Cookpad Parsed Corpus: a dataset of linguistically annotated recipes (Linguistic Annotation Workshop 2020)
Python
21
star
53

denv

Loads environment variables to `ENV` from `.env` file
Ruby
19
star
54

guard_against_physical_delete

guard_against_physical_delete is monkey patch for ActiveRecord. This patch prevent deleting record physically.
Ruby
19
star
55

2018-newgrads-engineer-portfolio

クックパッド 2018 年度新卒採用選考エントリーシート提出方法と、その時に利用するファイル一式です。
19
star
56

OkReport

Android library to submit reports without leaving the app.
Kotlin
18
star
57

cp8_cli

Cookpad Global CLI
Ruby
18
star
58

cookpad-internship-2019-summer

Swift
18
star
59

armg

Add MySQL geometry type to Active Record.
Ruby
18
star
60

StringsPatcher

An android lib for updating string resources on the fly
Kotlin
14
star
61

sisito

It is sisimai collected data frontend.
Ruby
14
star
62

rgossip2

Basic implementation of a gossip protocol. This is a porting of Java implementation. see http://code.google.com/p/gossip-protocol-java/
Ruby
13
star
63

Phakchi

Pact consumer client library in Swift
Swift
13
star
64

ecamo

SSL image proxy with JWT authentication
Rust
12
star
65

janiConverter

Online transcoder: from movie file to jani-format. Supports VAST integration
Ruby
12
star
66

session_store_relocator

Supports Rails session store relocation with duplicate write session data to multiple stores
Ruby
11
star
67

cookpad-internship-2017-summer

Jupyter Notebook
11
star
68

reuse_query_results

reuse mysql query results
Ruby
11
star
69

onesky-gradle-plugin

Kotlin
11
star
70

techconf2017-network

Ruby
10
star
71

aws-falcon-data-forwarder

CrowdStrike Falcon log forwarder from falcon S3 bucket to your S3 bucket
Go
10
star
72

cookpad-internship-2018-summer

Ruby
10
star
73

raven-transports-fluentd

Send error logs to sentry via fluentd
Ruby
10
star
74

prism

Streaming loader for Amazon Redshift Spectrum
Java
10
star
75

2016-internship-engineer-portfolio

クックパッド 2016 インターンの応募方法と、その時に利用するファイル一式です。
9
star
76

2017-internship-engineer-portfolio

クックパッド サマーインターンシップ 2017 への応募方法についての説明です。
9
star
77

minerva

Serverless Log Search Architecture for Security Monitoring based on Amazon Athena
Go
8
star
78

oicy-taste

design information of condiment dispenser "OiCy Taste"
C++
8
star
79

swift-user-defaults

A series of Swift friendly utilities for Foundation's UserDefaults class.
Swift
8
star
80

spring-internship-2021-lecture-code

TypeScript
7
star
81

dango

A service for managing i18n
Elixir
6
star
82

garage-doorkeeper

Garage extension to integrate doorkeeper gem
Ruby
5
star
83

griffin-interceptors

Ruby
5
star
84

cookpad_departure_defaults

Ruby
5
star
85

cookpad-internship-2020-summer-ios

Swift
4
star
86

android-studio-templates

Provides a set of templates for scaffolding architectural repetitive tasks.
Kotlin
4
star
87

cookpad-performance

Some performance tools we use across our Rails applications
Ruby
4
star
88

cookpad-internship-2020-summer-web

Ruby
4
star
89

barbeque_client

barbeque client for Ruby
Ruby
4
star
90

wait-side-car

Wait essential side-car containers to be available.
Go
4
star
91

rsolr_cookpad

A Ruby client for Apache Solr (saving weights of the repository by cutting down disused branches and tags)
Ruby
3
star
92

cookpad-internship-2021-summer-ios

Swift
3
star
93

package-scanner-android

WIP
Java
3
star
94

mirin

Redirection Service
Haskell
3
star
95

cookpad_mysql_defaults

Cookpad's MySQL defaults
Ruby
3
star
96

cookpad-internship-1day-ruby

Ruby
3
star
97

SocialConnect

OAuth library for Android: retrieves OAuth tokens from multiple social networks.
Kotlin
3
star
98

github-app-installation-token-action

A GitHub Action that can be used to generate scoped credentials for use within your workflow using an App integration.
JavaScript
3
star
99

bitrise-step-github-app-installation-token

Go
2
star
100

rubyists-on-rails

Passenger Announcement for Rubyists on Rails.
2
star