• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package io.flutter.plugin.common;
6 
7 import io.flutter.BuildConfig;
8 
9 import android.support.annotation.Nullable;
10 import android.util.Log;
11 
12 /**
13  * An implementation of {@link MethodChannel.Result} that writes error results
14  * to the Android log.
15  */
16 public class ErrorLogResult implements MethodChannel.Result {
17     private String tag;
18     private int level;
19 
ErrorLogResult(String tag)20     public ErrorLogResult(String tag) {
21         this(tag, Log.WARN);
22     }
23 
ErrorLogResult(String tag, int level)24     public ErrorLogResult(String tag, int level) {
25         this.tag = tag;
26         this.level = level;
27     }
28 
29     @Override
success(@ullable Object result)30     public void success(@Nullable Object result) {}
31 
32     @Override
error(String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails)33     public void error(String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) {
34         String details = (errorDetails != null) ? " details: " + errorDetails : "";
35         if (level >= Log.WARN || BuildConfig.DEBUG) {
36             Log.println(level, tag, errorMessage + details);
37         }
38     }
39 
40     @Override
notImplemented()41     public void notImplemented() {
42         if (level >= Log.WARN || BuildConfig.DEBUG) {
43             Log.println(level, tag, "method not implemented");
44         }
45     }
46 }
47