ErrorLogResult.java 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugin.common;

import android.support.annotation.Nullable;
import android.util.Log;

/**
 * An implementation of {@link MethodChannel.Result} that writes error results
 * to the Android log.
 */
public class ErrorLogResult implements MethodChannel.Result {
    private String tag;
    private int level;

    public ErrorLogResult(String tag) {
        this(tag, Log.WARN);
    }

    public ErrorLogResult(String tag, int level) {
        this.tag = tag;
        this.level = level;
    }

    @Override
    public void success(@Nullable Object result) {}

    @Override
    public void error(String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) {
        String details = (errorDetails != null) ? " details: " + errorDetails : "";
        Log.println(level, tag, errorMessage + details);
    }

    @Override
    public void notImplemented() {
      Log.println(level, tag, "method not implemented");
    }
}