Skip to content

Commit 068fd30

Browse files
committed
Refactor the logger (#144)
* Rewrite tizen_log in the C++ style * Convert logs to streams * Rename tizen_log to logger * Change min logging level to Debug when --verbose-logging is set * Resolve conflicts & additional clean-up
1 parent fc8de20 commit 068fd30

25 files changed

+353
-441
lines changed

shell/platform/tizen/BUILD.gn

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ _flutter_tizen_source = [
3737
"flutter_tizen_engine.cc",
3838
"flutter_tizen_texture_registrar.cc",
3939
"key_event_handler.cc",
40+
"logger.cc",
4041
"tizen_event_loop.cc",
4142
"tizen_input_method_context.cc",
4243
"tizen_renderer.cc",
@@ -133,7 +134,6 @@ template("embedder_for_profile") {
133134
"external_texture_pixel_gl.cc",
134135
"external_texture_surface_gl.cc",
135136
"system_utils_tizen.cc",
136-
"tizen_log.cc",
137137
]
138138

139139
libs = _libs_minimum
@@ -250,7 +250,6 @@ template("embedder_executable") {
250250
"external_texture_pixel_gl_stub.cc",
251251
"external_texture_surface_gl_stub.cc",
252252
"system_utils_linux.cc",
253-
"tizen_log_stub.cc",
254253
"tizen_renderer_evas_gl.cc",
255254
]
256255

shell/platform/tizen/channels/key_event_channel.cc

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <map>
88

99
#include "flutter/shell/platform/common/json_message_codec.h"
10-
#include "flutter/shell/platform/tizen/tizen_log.h"
1110

1211
namespace flutter {
1312

shell/platform/tizen/channels/lifecycle_channel.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "lifecycle_channel.h"
66

77
#include "flutter/shell/platform/tizen/channels/string_codec.h"
8-
#include "flutter/shell/platform/tizen/tizen_log.h"
8+
#include "flutter/shell/platform/tizen/logger.h"
99

1010
namespace flutter {
1111

@@ -29,22 +29,22 @@ LifecycleChannel::LifecycleChannel(BinaryMessenger* messenger)
2929
LifecycleChannel::~LifecycleChannel() {}
3030

3131
void LifecycleChannel::AppIsInactive() {
32-
FT_LOGI("Sending %s message.", kInactive);
32+
FT_LOG(Info) << "Sending " << kInactive << " message.";
3333
channel_->Send(EncodableValue(kInactive));
3434
}
3535

3636
void LifecycleChannel::AppIsResumed() {
37-
FT_LOGI("Sending %s message.", kResumed);
37+
FT_LOG(Info) << "Sending " << kResumed << " message.";
3838
channel_->Send(EncodableValue(kResumed));
3939
}
4040

4141
void LifecycleChannel::AppIsPaused() {
42-
FT_LOGI("Sending %s message.", kPaused);
42+
FT_LOG(Info) << "Sending " << kPaused << " message.";
4343
channel_->Send(EncodableValue(kPaused));
4444
}
4545

4646
void LifecycleChannel::AppIsDetached() {
47-
FT_LOGI("Sending %s message.", kDetached);
47+
FT_LOG(Info) << "Sending " << kDetached << " message.";
4848
channel_->Send(EncodableValue(kDetached));
4949
}
5050

shell/platform/tizen/channels/platform_channel.cc

+10-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <map>
1111

1212
#include "flutter/shell/platform/common/json_method_codec.h"
13-
#include "flutter/shell/platform/tizen/tizen_log.h"
13+
#include "flutter/shell/platform/tizen/logger.h"
1414

1515
namespace flutter {
1616

@@ -99,12 +99,7 @@ class FeedbackManager {
9999
FeedbackManager& operator=(const FeedbackManager&) = delete;
100100

101101
ResultCode Play(FeedbackType type, FeedbackPattern pattern) {
102-
FT_LOGI("Enter FeedbackManager::Play(): type: [%d], pattern: [%d]",
103-
static_cast<int>(type), static_cast<int>(pattern));
104-
105102
if (ResultCode::kOk != initialization_status_) {
106-
FT_LOGE("Cannot run Play(): initialization_status_: [%d]",
107-
static_cast<int>(initialization_status_));
108103
return initialization_status_;
109104
}
110105

@@ -113,8 +108,8 @@ class FeedbackManager {
113108
if (FEEDBACK_ERROR_NONE == ret) {
114109
return ResultCode::kOk;
115110
}
116-
FT_LOGE("feedback_play_type() failed with error: [%d] (%s)", ret,
117-
get_error_message(ret));
111+
FT_LOG(Error) << "feedback_play_type() failed with error: "
112+
<< get_error_message(ret);
118113

119114
return NativeErrorToResultCode(ret);
120115
}
@@ -139,8 +134,8 @@ class FeedbackManager {
139134
FeedbackManager() {
140135
auto ret = feedback_initialize();
141136
if (FEEDBACK_ERROR_NONE != ret) {
142-
FT_LOGE("feedback_initialize() failed with error: [%d] (%s)", ret,
143-
get_error_message(ret));
137+
FT_LOG(Error) << "feedback_initialize() failed with error: "
138+
<< get_error_message(ret);
144139
initialization_status_ = NativeErrorToResultCode(ret);
145140
return;
146141
}
@@ -151,8 +146,8 @@ class FeedbackManager {
151146
~FeedbackManager() {
152147
auto ret = feedback_deinitialize();
153148
if (FEEDBACK_ERROR_NONE != ret) {
154-
FT_LOGE("feedback_deinitialize() failed with error: [%d] (%s)", ret,
155-
get_error_message(ret));
149+
FT_LOG(Error) << "feedback_deinitialize() failed with error: "
150+
<< get_error_message(ret);
156151
return;
157152
}
158153
}
@@ -252,7 +247,7 @@ void PlatformChannel::HandleMethodCall(
252247
const auto error_cause =
253248
FeedbackManager::GetErrorMessage(ret, kPlaySoundMethod, pattern_str);
254249
const std::string error_message = "Could not play sound";
255-
FT_LOGE("%s: %s", error_cause.c_str(), error_message.c_str());
250+
FT_LOG(Error) << error_cause << ": " << error_message;
256251

257252
result->Error(error_cause, error_message);
258253

@@ -280,7 +275,7 @@ void PlatformChannel::HandleMethodCall(
280275
FeedbackManager::GetErrorMessage(ret, vibrate_variant_name);
281276
const std::string error_message = "Could not vibrate";
282277

283-
FT_LOGE("%s: %s", error_cause.c_str(), error_message.c_str());
278+
FT_LOG(Error) << error_cause << ": " << error_message;
284279

285280
result->Error(error_cause, error_message);
286281
} else if (method == kGetClipboardDataMethod) {
@@ -330,7 +325,7 @@ void PlatformChannel::HandleMethodCall(
330325
} else if (method == kSetSystemUIOverlayStyleMethod) {
331326
result->NotImplemented();
332327
} else {
333-
FT_LOGI("Unimplemented method: %s", method.c_str());
328+
FT_LOG(Info) << "Unimplemented method: " << method;
334329
result->NotImplemented();
335330
}
336331
}

shell/platform/tizen/channels/platform_view_channel.cc

+4-9
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h"
1010
#include "flutter/shell/platform/common/json_method_codec.h"
1111
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
12+
#include "flutter/shell/platform/tizen/logger.h"
1213
#include "flutter/shell/platform/tizen/public/flutter_platform_view.h"
13-
#include "flutter/shell/platform/tizen/tizen_log.h"
1414

1515
namespace flutter {
1616

@@ -121,9 +121,7 @@ void PlatformViewChannel::HandleMethodCall(
121121
return;
122122
}
123123

124-
FT_LOGI(
125-
"PlatformViewChannel create viewType: %s id: %d width: %f height: %f ",
126-
view_type.c_str(), view_id, width, height);
124+
FT_LOG(Info) << "Creating a platform view: " << view_type;
127125
RemoveViewInstanceIfNeeded(view_id);
128126

129127
EncodableMap values = std::get<EncodableMap>(arguments);
@@ -149,7 +147,7 @@ void PlatformViewChannel::HandleMethodCall(
149147
result->Error("Can't create a webview instance!!");
150148
}
151149
} else {
152-
FT_LOGE("can't find view type = %s", view_type.c_str());
150+
FT_LOG(Error) << "Can't find view type: " << view_type;
153151
result->Error("Can't find view type");
154152
}
155153
} else if (method == "clearFocus") {
@@ -228,11 +226,8 @@ void PlatformViewChannel::HandleMethodCall(
228226
}
229227

230228
result->Success();
231-
} else if (method == "setDirection") {
232-
FT_LOGW("PlatformViewChannel setDirection - not implemented");
233-
result->NotImplemented();
234229
} else {
235-
FT_LOGW("Unimplemented method: %s", method.c_str());
230+
FT_LOG(Warn) << "Unimplemented method: " << method;
236231
result->NotImplemented();
237232
}
238233
} else {

shell/platform/tizen/channels/text_input_channel.cc

+15-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "flutter/shell/platform/common/json_method_codec.h"
1010
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
11-
#include "flutter/shell/platform/tizen/tizen_log.h"
11+
#include "flutter/shell/platform/tizen/logger.h"
1212

1313
namespace flutter {
1414

@@ -46,6 +46,7 @@ bool IsASCIIPrintableKey(char c) {
4646
}
4747
return false;
4848
}
49+
4950
} // namespace
5051

5152
TextInputChannel::TextInputChannel(BinaryMessenger* messenger,
@@ -63,7 +64,7 @@ TextInputChannel::TextInputChannel(BinaryMessenger* messenger,
6364

6465
// Set input method callbacks
6566
input_method_context_->SetOnCommitCallback([this](std::string str) -> void {
66-
FT_LOGI("OnCommit str[%s]", str.data());
67+
FT_LOG(Debug) << "OnCommit: " << str;
6768
text_editing_context_.edit_status_ = EditStatus::kCommit;
6869
ConsumeLastPreedit();
6970
active_model_->AddText(str);
@@ -95,9 +96,10 @@ TextInputChannel::TextInputChannel(BinaryMessenger* messenger,
9596
active_model_->selection().base();
9697
text_editing_context_.has_preedit_ = true;
9798
SendStateUpdate(*active_model_);
98-
FT_LOGI("preedit start pos[%d], preedit end pos[%d]",
99-
text_editing_context_.preedit_start_pos_,
100-
text_editing_context_.preedit_end_pos_);
99+
FT_LOG(Debug) << "Preedit start position: "
100+
<< text_editing_context_.preedit_start_pos_
101+
<< ", end position: "
102+
<< text_editing_context_.preedit_end_pos_;
101103
}
102104
});
103105

@@ -133,8 +135,7 @@ void TextInputChannel::HandleMethodCall(
133135
const MethodCall<rapidjson::Document>& method_call,
134136
std::unique_ptr<MethodResult<rapidjson::Document>> result) {
135137
const std::string& method = method_call.method_name();
136-
137-
FT_LOGI("Handle Method : %s", method.data());
138+
FT_LOG(Debug) << "Handle a method: " << method;
138139

139140
if (method.compare(kShowMethod) == 0) {
140141
input_method_context_->ShowInputPannel();
@@ -253,7 +254,7 @@ void TextInputChannel::SendStateUpdate(const TextInputModel& model) {
253254
kTextKey, rapidjson::Value(model.GetText(), allocator).Move(), allocator);
254255
args->PushBack(editing_state, allocator);
255256

256-
FT_LOGI("Send text[%s]", model.GetText().data());
257+
FT_LOG(Info) << "Send text: " << model.GetText();
257258
channel_->InvokeMethod(kUpdateEditingStateMethod, std::move(args));
258259
}
259260

@@ -268,7 +269,7 @@ bool TextInputChannel::FilterEvent(Ecore_Event_Key* event) {
268269
// FIXME: Only for wearable.
269270
if (is_ime && strcmp(event->key, "Select") == 0) {
270271
text_editing_context_.is_in_select_mode_ = true;
271-
FT_LOGI("Set select mode[true]");
272+
FT_LOG(Debug) << "Entering select mode.";
272273
}
273274
#else
274275
bool is_ime = strcmp(ecore_device_name_get(event->dev), "ime") == 0;
@@ -277,7 +278,7 @@ bool TextInputChannel::FilterEvent(Ecore_Event_Key* event) {
277278
if (ShouldNotFilterEvent(event->key, is_ime)) {
278279
ResetTextEditingContext();
279280
input_method_context_->ResetInputMethodContext();
280-
FT_LOGW("Force redirect IME key-event[%s] to fallback", event->keyname);
281+
FT_LOG(Info) << "Force redirect an IME key event: " << event->keyname;
281282
return false;
282283
}
283284

@@ -292,7 +293,7 @@ bool TextInputChannel::FilterEvent(Ecore_Event_Key* event) {
292293
text_editing_context_.is_in_select_mode_) {
293294
text_editing_context_.is_in_select_mode_ = false;
294295
handled = true;
295-
FT_LOGI("Set select mode[false]");
296+
FT_LOG(Debug) << "Leaving select mode.";
296297
}
297298
#endif
298299

@@ -303,7 +304,7 @@ void TextInputChannel::HandleUnfilteredEvent(Ecore_Event_Key* event) {
303304
#ifdef MOBILE_PROFILE
304305
// FIXME: Only for mobile.
305306
if (text_editing_context_.edit_status_ == EditStatus::kPreeditEnd) {
306-
FT_LOGW("Ignore key-event[%s]!", event->keyname);
307+
FT_LOG(Warn) << "Ignore a key event: " << event->keyname;
307308
ResetTextEditingContext();
308309
return;
309310
}
@@ -372,8 +373,8 @@ void TextInputChannel::ConsumeLastPreedit() {
372373
text_editing_context_.preedit_start_pos_;
373374
active_model_->DeleteSurrounding(-count, count);
374375
std::string after = active_model_->GetText();
375-
FT_LOGI("Consume last preedit count:[%d] text:[%s] -> [%s]", count,
376-
before.data(), after.data());
376+
FT_LOG(Debug) << "Last preedit count: " << count << ", text: " << before
377+
<< " -> " << after;
377378
SendStateUpdate(*active_model_);
378379
}
379380
text_editing_context_.has_preedit_ = false;

shell/platform/tizen/external_texture_pixel_gl.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "flutter/shell/platform/tizen/external_texture_pixel_gl.h"
5+
#include "external_texture_pixel_gl.h"
66

77
#ifdef TIZEN_RENDERER_EVAS_GL
88
#undef EFL_BETA_API_SUPPORT

shell/platform/tizen/external_texture_pixel_gl_stub.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "flutter/shell/platform/tizen/external_texture_pixel_gl.h"
5+
#include "external_texture_pixel_gl.h"
66

77
namespace flutter {
88

shell/platform/tizen/external_texture_surface_gl.cc

+7-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#include "external_texture_surface_gl.h"
66

7-
#include "flutter/shell/platform/common/public/flutter_texture_registrar.h"
8-
97
#ifdef TIZEN_RENDERER_EVAS_GL
108
#undef EFL_BETA_API_SUPPORT
119
#include <Evas_GL_GLES3_Helpers.h>
@@ -20,7 +18,8 @@ EVAS_GL_GLOBAL_GLES3_DECLARE();
2018

2119
#include <tbm_surface.h>
2220

23-
#include "flutter/shell/platform/tizen/tizen_log.h"
21+
#include "flutter/shell/platform/common/public/flutter_texture_registrar.h"
22+
#include "flutter/shell/platform/tizen/logger.h"
2423

2524
namespace flutter {
2625

@@ -60,20 +59,20 @@ bool ExternalTextureSurfaceGL::PopulateTexture(
6059
const FlutterDesktopGpuBuffer* gpu_buffer =
6160
texture_callback_(width, height, user_data_);
6261
if (!gpu_buffer) {
63-
FT_LOGI("[texture id:%ld] gpu_buffer is null", texture_id_);
62+
FT_LOG(Info) << "gpu_buffer is null for texture ID: " << texture_id_;
6463
return false;
6564
}
6665

6766
if (!gpu_buffer->buffer) {
68-
FT_LOGI("[texture id:%ld] tbm_surface_ is null", texture_id_);
67+
FT_LOG(Info) << "tbm_surface is null for texture ID: " << texture_id_;
6968
return false;
7069
}
7170
const tbm_surface_h tbm_surface =
7271
reinterpret_cast<tbm_surface_h>(const_cast<void*>(gpu_buffer->buffer));
7372

7473
tbm_surface_info_s info;
7574
if (tbm_surface_get_info(tbm_surface, &info) != TBM_SURFACE_ERROR_NONE) {
76-
FT_LOGI("[texture id:%ld] tbm_surface is invalid", texture_id_);
75+
FT_LOG(Info) << "tbm_surface is invalid for texture ID: " << texture_id_;
7776
return false;
7877
}
7978

@@ -114,8 +113,8 @@ bool ExternalTextureSurfaceGL::PopulateTexture(
114113
EGL_NATIVE_SURFACE_TIZEN, tbm_surface, attribs);
115114

116115
if (!egl_src_image) {
117-
FT_LOGE("[texture id:%ld] egl_src_image create fail!!, errorcode == %d",
118-
texture_id_, eglGetError());
116+
FT_LOG(Error) << "eglCreateImageKHR failed with an error " << eglGetError()
117+
<< " for texture ID: " << texture_id_;
119118
return false;
120119
}
121120
if (state_->gl_texture == 0) {

0 commit comments

Comments
 (0)