From: Alexis Laferrière Date: Fri, 2 May 2014 02:30:28 +0000 (-0400) Subject: lib: add log features from mnit_app::android_app to ::android X-Git-Tag: v0.6.6~61^2 X-Git-Url: http://nitlanguage.org lib: add log features from mnit_app::android_app to ::android Signed-off-by: Alexis Laferrière --- diff --git a/lib/android/android.nit b/lib/android/android.nit index add5bd7..0d9bfcb 100644 --- a/lib/android/android.nit +++ b/lib/android/android.nit @@ -14,13 +14,24 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Targets the Android platform +# Android services and implementation of app.nit # # To use this module and compile for Android, you must install the # Android SDK (with API level 10) and NDK (with the API level 9). # The tools `android`, `ndk-build` and `ant` must be in your PATH. # -# Will, in the near future, provide services specific to Android. +# This module provides basic logging facilities, advanced logging can be +# achieved by importing `android::log`. module android import platform +private import log + +# Uses Android logs to print everything +redef fun print(text) do log_write(priority_info, app.log_prefix.to_cstring, text.to_s.to_cstring) + +redef class App + redef fun log_error(msg) do log_write(priority_error, log_prefix.to_cstring, msg.to_cstring) + + redef fun log_warning(msg) do log_write(priority_warn, log_prefix.to_cstring, msg.to_cstring) +end diff --git a/lib/android/log.nit b/lib/android/log.nit new file mode 100644 index 0000000..30beb62 --- /dev/null +++ b/lib/android/log.nit @@ -0,0 +1,53 @@ +# This file is part of NIT (http://www.nitlanguage.org). +# +# Copyright 2014 Alexis Laferrière +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Advanced Android logging services +module log + +import platform + +in "C" `{ + #include +`} + +# Default Android log priority +protected fun priority_default: Int do return 1 + +# Verbose Android log priority +protected fun priority_verbose: Int do return 2 + +# Debug Android log priority +protected fun priority_debug: Int do return 3 + +# Info Android log priority +protected fun priority_info: Int do return 4 + +# Warn Android log priority +protected fun priority_warn: Int do return 5 + +# Error Android log priority +protected fun priority_error: Int do return 6 + +# Fatal Android log priority +protected fun priority_fatal: Int do return 7 + +# Silent Android log priority +protected fun priority_silent: Int do return 8 + +# Write `text` to Android log at priority `level` with tag `tag` +protected fun log_write(level: Int, tag, text: NativeString) `{ + __android_log_write(level, tag, text); +`} diff --git a/lib/mnit_android/android_app.nit b/lib/mnit_android/android_app.nit index 6a1fd89..64728bd 100644 --- a/lib/mnit_android/android_app.nit +++ b/lib/mnit_android/android_app.nit @@ -373,13 +373,6 @@ extern class AndroidKeyEvent in "C" `{AInputEvent *`} fun is_search_key: Bool do return key_code == 84 end -redef class Object - # Uses Android logs for every print - redef fun print(text: Object) is extern import Object.to_s, String.to_cstring `{ - __android_log_print(ANDROID_LOG_INFO, "mnit print", "%s", String_to_cstring(Object_to_s(text))); - `} -end - redef class App redef type IE: AndroidInputEvent redef type D: Opengles1Display @@ -393,13 +386,6 @@ redef class App var eventqueue: ASensorEventQueue var sensors_support_enabled writable = false - redef fun log_warning(msg) is extern import String.to_cstring `{ - LOGW("%s", String_to_cstring(msg)); - `} - redef fun log_info(msg) is extern import String.to_cstring `{ - LOGI("%s", String_to_cstring(msg)); - `} - redef fun init_window do super