Bug 1047277 - Hide HAL's logging macros from the public headers and convert all components to use them. r=dhylands
authorGabriele Svelto <gsvelto@mozilla.com>
Wed, 24 Sep 2014 15:23:18 +0200
changeset 207493 932a92a16c29d31db9bb9b1bed8d9d20844ce405
parent 207492 d0be07d7cf1b10d4706290569d2d054cdbf34d4f
child 207494 ea64366d660fd699fa726b933e647974d20aed8d
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersdhylands
bugs1047277
milestone35.0a1
Bug 1047277 - Hide HAL's logging macros from the public headers and convert all components to use them. r=dhylands
hal/Hal.cpp
hal/Hal.h
hal/HalLog.h
hal/HalWakeLock.cpp
hal/fallback/FallbackAlarm.cpp
hal/fallback/FallbackProcessPriority.cpp
hal/fallback/FallbackThreadPriority.cpp
hal/gonk/GonkDiskSpaceWatcher.cpp
hal/gonk/GonkFMRadio.cpp
hal/gonk/GonkHal.cpp
hal/gonk/GonkSensor.cpp
hal/gonk/GonkSwitch.cpp
hal/gonk/UeventPoller.cpp
hal/linux/UPowerClient.cpp
hal/sandbox/SandboxHal.cpp
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=2 ts=8 et ft=cpp : */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "Hal.h"
 #include "HalImpl.h"
+#include "HalLog.h"
 #include "HalSandbox.h"
 #include "nsThreadUtils.h"
 #include "nsXULAppAPI.h"
 #include "mozilla/Observer.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDOMWindow.h"
@@ -124,17 +125,17 @@ Vibrate(const nsTArray<uint32_t>& patter
 
   // Only active windows may start vibrations.  If |id| hasn't gone
   // through the IPC layer -- that is, if our caller is the outside
   // world, not hal_proxy -- check whether the window is active.  If
   // |id| has gone through IPC, don't check the window's visibility;
   // only the window corresponding to the bottommost process has its
   // visibility state set correctly.
   if (!id.HasTraveledThroughIPC() && !WindowIsActive(id.GetWindow())) {
-    HAL_LOG(("Vibrate: Window is inactive, dropping vibrate."));
+    HAL_LOG("Vibrate: Window is inactive, dropping vibrate.");
     return;
   }
 
   if (!InSandbox()) {
     if (!gLastIDToVibrate) {
       InitLastIDToVibrate();
     }
     *gLastIDToVibrate = id.AsArray();
--- a/hal/Hal.h
+++ b/hal/Hal.h
@@ -8,17 +8,16 @@
 #define mozilla_Hal_h
 
 #include "mozilla/hal_sandbox/PHal.h"
 #include "mozilla/HalTypes.h"
 #include "base/basictypes.h"
 #include "mozilla/Observer.h"
 #include "mozilla/Types.h"
 #include "nsTArray.h"
-#include "prlog.h"
 #include "mozilla/dom/MozPowerManagerBinding.h"
 #include "mozilla/dom/battery/Types.h"
 #include "mozilla/dom/network/Types.h"
 #include "mozilla/dom/power/Types.h"
 #include "mozilla/hal_sandbox/PHal.h"
 #include "mozilla/dom/ScreenOrientation.h"
 #include "mozilla/HalScreenConfiguration.h"
 
@@ -42,20 +41,16 @@ class nsIDOMWindow;
 namespace mozilla {
 
 namespace hal {
 
 typedef Observer<void_t> AlarmObserver;
 
 class WindowIdentifier;
 
-extern PRLogModuleInfo *GetHalLog();
-#define HAL_LOG(msg) PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_DEBUG, msg)
-#define HAL_ERR(msg) PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_ERROR, msg)
-
 typedef Observer<int64_t> SystemClockChangeObserver;
 typedef Observer<SystemTimezoneChangeInformation> SystemTimezoneChangeObserver;
 
 } // namespace hal
 
 namespace MOZ_HAL_NAMESPACE {
 
 /**
new file mode 100644
--- /dev/null
+++ b/hal/HalLog.h
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 ts=8 et ft=cpp : */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_HalLog_h
+#define mozilla_HalLog_h
+
+#include "prlog.h"
+
+/*
+ * HalLog.h contains internal macros and functions used for logging.
+ *
+ * This should be considered a private include and not used in non-HAL code.
+ * To enable logging in non-debug builds define the PR_FORCE_LOG macro here.
+ */
+
+namespace mozilla {
+
+namespace hal {
+
+extern PRLogModuleInfo *GetHalLog();
+#define HAL_LOG(...) \
+  PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_DEBUG, (__VA_ARGS__))
+#define HAL_ERR(...) \
+  PR_LOG(mozilla::hal::GetHalLog(), PR_LOG_ERROR, (__VA_ARGS__))
+
+} // namespace hal
+
+} // namespace mozilla
+
+#endif // mozilla_HalLog_h
--- a/hal/HalWakeLock.cpp
+++ b/hal/HalWakeLock.cpp
@@ -1,14 +1,14 @@
 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "mozilla/Hal.h"
+#include "Hal.h"
 #include "mozilla/HalWakeLock.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/dom/ContentParent.h"
 #include "nsClassHashtable.h"
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
 #include "nsIPropertyBag2.h"
--- a/hal/fallback/FallbackAlarm.cpp
+++ b/hal/fallback/FallbackAlarm.cpp
@@ -49,18 +49,17 @@ DisableAlarm()
     sTimer->Cancel();
   }
 }
 
 bool
 SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
 {
   if (!sTimer) {
-    HAL_LOG(("We should have enabled the alarm"));
-    MOZ_ASSERT(false);
+    MOZ_ASSERT(false, "We should have enabled the alarm");
     return false;
   }
 
   // Do the math to convert aSeconds and aNanoseconds into milliseconds since
   // the epoch.
   int64_t milliseconds = static_cast<int64_t>(aSeconds) * 1000 +
                          static_cast<int64_t>(aNanoseconds) / 1000000;
 
--- a/hal/fallback/FallbackProcessPriority.cpp
+++ b/hal/fallback/FallbackProcessPriority.cpp
@@ -1,24 +1,25 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "Hal.h"
+#include "HalLog.h"
 
 using namespace mozilla::hal;
 
 namespace mozilla {
 namespace hal_impl {
 
 void
 SetProcessPriority(int aPid,
                    ProcessPriority aPriority,
                    ProcessCPUPriority aCPUPriority,
                    uint32_t aBackgroundLRU)
 {
-  HAL_LOG(("FallbackProcessPriority - SetProcessPriority(%d, %s, %u)\n",
-           aPid, ProcessPriorityToString(aPriority, aCPUPriority),
-           aBackgroundLRU));
+  HAL_LOG("FallbackProcessPriority - SetProcessPriority(%d, %s, %u)\n",
+          aPid, ProcessPriorityToString(aPriority, aCPUPriority),
+          aBackgroundLRU);
 }
 
 } // hal_impl
 } // namespace mozilla
--- a/hal/fallback/FallbackThreadPriority.cpp
+++ b/hal/fallback/FallbackThreadPriority.cpp
@@ -1,20 +1,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "Hal.h"
+#include "HalLog.h"
 
 using namespace mozilla::hal;
 
 namespace mozilla {
 namespace hal_impl {
 
 void
 SetCurrentThreadPriority(ThreadPriority aPriority)
 {
-  HAL_LOG(("FallbackThreadPriority - SetCurrentThreadPriority(%d)\n",
-           ThreadPriorityToString(aPriority)));
+  HAL_LOG("FallbackThreadPriority - SetCurrentThreadPriority(%d)\n",
+          ThreadPriorityToString(aPriority));
 }
 
 } // hal_impl
 } // namespace mozilla
--- a/hal/gonk/GonkDiskSpaceWatcher.cpp
+++ b/hal/gonk/GonkDiskSpaceWatcher.cpp
@@ -163,17 +163,17 @@ GonkDiskSpaceWatcher::DoStart()
 {
   NS_ASSERTION(XRE_GetIOMessageLoop() == MessageLoopForIO::current(),
                "Not on the correct message loop");
 
   mFd = fanotify_init(FAN_CLASS_NOTIF, FAN_CLOEXEC);
   if (mFd == -1) {
     NS_WARNING("Error calling inotify_init()");
     if (errno == ENOSYS) {
-      printf_stderr("Warning: No fanotify support in this device's kernel.\n");
+      NS_WARNING("Warning: No fanotify support in this device's kernel.\n");
     }
     return;
   }
 
   if (fanotify_mark(mFd, FAN_MARK_ADD | FAN_MARK_MOUNT, FAN_CLOSE,
                     0, kWatchedPath) < 0) {
     NS_WARNING("Error calling fanotify_mark");
     close(mFd);
@@ -236,18 +236,17 @@ GonkDiskSpaceWatcher::OnFileCanReadWitho
 
   // Bail out if the file is busy.
   if (len < 0 && errno == ETXTBSY) {
     return;
   }
 
   // We should get an exact multiple of fanotify_event_metadata
   if (len <= 0 || (len % FAN_EVENT_METADATA_LEN != 0)) {
-    printf_stderr("About to crash: fanotify_event_metadata read error.");
-    MOZ_CRASH();
+    MOZ_CRASH("About to crash: fanotify_event_metadata read error.");
   }
 
   fem = reinterpret_cast<fanotify_event_metadata *>(buf);
 
   while (FAN_EVENT_OK(fem, len)) {
     rc = fstatfs(fem->fd, &sfs);
     if (rc < 0) {
       NS_WARNING("Unable to stat fan_notify fd");
--- a/hal/gonk/GonkFMRadio.cpp
+++ b/hal/gonk/GonkFMRadio.cpp
@@ -9,16 +9,17 @@
  * 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.
  */
 
 #include "Hal.h"
+#include "HalLog.h"
 #include "tavarua.h"
 #include "nsThreadUtils.h"
 #include "mozilla/FileUtils.h"
 
 #include <cutils/properties.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <linux/videodev2.h>
@@ -108,52 +109,52 @@ initMsmFMRadio(hal::FMRadioSettings &aIn
     property_get("hw.fm.init", value, "0");
     if (!strcmp(value, "1")) {
       break;
     }
   }
 
   rc = setControl(V4L2_CID_PRIVATE_TAVARUA_STATE, FM_RECV);
   if (rc < 0) {
-    HAL_LOG(("Unable to turn on radio |%s|", strerror(errno)));
+    HAL_LOG("Unable to turn on radio |%s|", strerror(errno));
     return;
   }
 
   int preEmphasis = aInfo.preEmphasis() <= 50;
   rc = setControl(V4L2_CID_PRIVATE_TAVARUA_EMPHASIS, preEmphasis);
   if (rc) {
-    HAL_LOG(("Unable to configure preemphasis"));
+    HAL_LOG("Unable to configure preemphasis");
     return;
   }
 
   rc = setControl(V4L2_CID_PRIVATE_TAVARUA_RDS_STD, 0);
   if (rc) {
-    HAL_LOG(("Unable to configure RDS"));
+    HAL_LOG("Unable to configure RDS");
     return;
   }
 
   int spacing;
   switch (aInfo.spaceType()) {
   case 50:
     spacing = FM_CH_SPACE_50KHZ;
     break;
   case 100:
     spacing = FM_CH_SPACE_100KHZ;
     break;
   case 200:
     spacing = FM_CH_SPACE_200KHZ;
     break;
   default:
-    HAL_LOG(("Unsupported space value - %d", aInfo.spaceType()));
+    HAL_LOG("Unsupported space value - %d", aInfo.spaceType());
     return;
   }
 
   rc = setControl(V4L2_CID_PRIVATE_TAVARUA_SPACING, spacing);
   if (rc) {
-    HAL_LOG(("Unable to configure spacing"));
+    HAL_LOG("Unable to configure spacing");
     return;
   }
 
   /*
    * Frequency conversions
    *
    * HAL uses units of 1k for frequencies
    * V4L2 uses units of 62.5kHz
@@ -161,36 +162,36 @@ initMsmFMRadio(hal::FMRadioSettings &aIn
    */
 
   struct v4l2_tuner tuner = {0};
   tuner.rangelow = (aInfo.lowerLimit() * 10000) / 625;
   tuner.rangehigh = (aInfo.upperLimit() * 10000) / 625;
   tuner.audmode = V4L2_TUNER_MODE_STEREO;
   rc = ioctl(fd, VIDIOC_S_TUNER, &tuner);
   if (rc < 0) {
-    HAL_LOG(("Unable to adjust band limits"));
+    HAL_LOG("Unable to adjust band limits");
     return;
   }
 
   rc = setControl(V4L2_CID_PRIVATE_TAVARUA_REGION, TAVARUA_REGION_OTHER);
   if (rc < 0) {
-    HAL_LOG(("Unable to configure region"));
+    HAL_LOG("Unable to configure region");
     return;
   }
 
   // Some devices do not support analog audio routing. This should be
   // indicated by the 'ro.moz.fm.noAnalog' property at build time.
   char propval[PROPERTY_VALUE_MAX];
   property_get("ro.moz.fm.noAnalog", propval, "");
   bool noAnalog = !strcmp(propval, "true");
 
   rc = setControl(V4L2_CID_PRIVATE_TAVARUA_SET_AUDIO_PATH,
                   noAnalog ? FM_DIGITAL_PATH : FM_ANALOG_PATH);
   if (rc < 0) {
-    HAL_LOG(("Unable to set audio path"));
+    HAL_LOG("Unable to set audio path");
     return;
   }
 
   if (!noAnalog) {
     /* Set the mode for soc downloader */
     property_set("hw.fm.mode", "config_dac");
     /* Use analog mode FM */
     property_set("hw.fm.isAnalog", "true");
@@ -267,74 +268,74 @@ runMsmFMRadio(void *)
 }
 
 /* This runs on the main thread but most of the
  * initialization is pushed to the radio thread. */
 void
 EnableFMRadio(const hal::FMRadioSettings& aInfo)
 {
   if (sRadioEnabled) {
-    HAL_LOG(("Radio already enabled!"));
+    HAL_LOG("Radio already enabled!");
     return;
   }
 
   hal::FMRadioOperationInformation info;
   info.operation() = hal::FM_RADIO_OPERATION_ENABLE;
   info.status() = hal::FM_RADIO_OPERATION_STATUS_FAIL;
 
   mozilla::ScopedClose fd(open("/dev/radio0", O_RDWR));
   if (fd < 0) {
-    HAL_LOG(("Unable to open radio device"));
+    HAL_LOG("Unable to open radio device");
     hal::NotifyFMRadioStatus(info);
     return;
   }
 
   struct v4l2_capability cap;
   int rc = ioctl(fd, VIDIOC_QUERYCAP, &cap);
   if (rc < 0) {
-    HAL_LOG(("Unable to query radio device"));
+    HAL_LOG("Unable to query radio device");
     hal::NotifyFMRadioStatus(info);
     return;
   }
 
   sMsmFMMode = !strcmp((char *)cap.driver, "radio-tavarua") ||
       !strcmp((char *)cap.driver, "radio-iris");
-  HAL_LOG(("Radio: %s (%s)\n", cap.driver, cap.card));
+  HAL_LOG("Radio: %s (%s)\n", cap.driver, cap.card);
 
   if (!(cap.capabilities & V4L2_CAP_RADIO)) {
-    HAL_LOG(("/dev/radio0 isn't a radio"));
+    HAL_LOG("/dev/radio0 isn't a radio");
     hal::NotifyFMRadioStatus(info);
     return;
   }
 
   if (!(cap.capabilities & V4L2_CAP_TUNER)) {
-    HAL_LOG(("/dev/radio0 doesn't support the tuner interface"));
+    HAL_LOG("/dev/radio0 doesn't support the tuner interface");
     hal::NotifyFMRadioStatus(info);
     return;
   }
   sRadioSettings = aInfo;
 
   if (sMsmFMMode) {
     sRadioFD = fd.forget();
     sMsmFMVersion = cap.version;
     if (pthread_create(&sRadioThread, nullptr, runMsmFMRadio, nullptr)) {
-      HAL_LOG(("Couldn't create radio thread"));
+      HAL_LOG("Couldn't create radio thread");
       hal::NotifyFMRadioStatus(info);
     }
     return;
   }
 
   struct v4l2_tuner tuner = {0};
   tuner.type = V4L2_TUNER_RADIO;
   tuner.rangelow = (aInfo.lowerLimit() * 10000) / 625;
   tuner.rangehigh = (aInfo.upperLimit() * 10000) / 625;
   tuner.audmode = V4L2_TUNER_MODE_STEREO;
   rc = ioctl(fd, VIDIOC_S_TUNER, &tuner);
   if (rc < 0) {
-    HAL_LOG(("Unable to adjust band limits"));
+    HAL_LOG("Unable to adjust band limits");
   }
 
   int emphasis;
   switch (aInfo.preEmphasis()) {
   case 0:
     emphasis = V4L2_DEEMPHASIS_DISABLED;
     break;
   case 50:
@@ -344,17 +345,17 @@ EnableFMRadio(const hal::FMRadioSettings
     emphasis = V4L2_DEEMPHASIS_75_uS;
     break;
   default:
     MOZ_CRASH("Invalid preemphasis setting");
     break;
   }
   rc = setControl(V4L2_CID_TUNE_DEEMPHASIS, emphasis);
   if (rc < 0) {
-    HAL_LOG(("Unable to configure deemphasis"));
+    HAL_LOG("Unable to configure deemphasis");
   }
 
   sRadioFD = fd.forget();
   sRadioEnabled = true;
 
   info.status() = hal::FM_RADIO_OPERATION_STATUS_SUCCESS;
   hal::NotifyFMRadioStatus(info);
 }
@@ -365,17 +366,17 @@ DisableFMRadio()
   if (!sRadioEnabled)
     return;
 
   sRadioEnabled = false;
 
   if (sMsmFMMode) {
     int rc = setControl(V4L2_CID_PRIVATE_TAVARUA_STATE, FM_OFF);
     if (rc < 0) {
-      HAL_LOG(("Unable to turn off radio"));
+      HAL_LOG("Unable to turn off radio");
     }
 
     pthread_join(sRadioThread, nullptr);
   }
 
   close(sRadioFD);
 
   hal::FMRadioOperationInformation info;
@@ -403,17 +404,17 @@ FMRadioSeek(const hal::FMRadioSeekDirect
     return;
 
   NS_DispatchToMainThread(new RadioUpdate(hal::FM_RADIO_OPERATION_SEEK,
                                           rc < 0 ?
                                           hal::FM_RADIO_OPERATION_STATUS_FAIL :
                                           hal::FM_RADIO_OPERATION_STATUS_SUCCESS));
 
   if (rc < 0) {
-    HAL_LOG(("Could not initiate hardware seek"));
+    HAL_LOG("Could not initiate hardware seek");
     return;
   }
 
   NS_DispatchToMainThread(new RadioUpdate(hal::FM_RADIO_OPERATION_TUNE,
                                           hal::FM_RADIO_OPERATION_STATUS_SUCCESS));
 }
 
 void
@@ -421,34 +422,34 @@ GetFMRadioSettings(hal::FMRadioSettings*
 {
   if (!sRadioEnabled) {
     return;
   }
 
   struct v4l2_tuner tuner = {0};
   int rc = ioctl(sRadioFD, VIDIOC_G_TUNER, &tuner);
   if (rc < 0) {
-    HAL_LOG(("Could not query fm radio for settings"));
+    HAL_LOG("Could not query fm radio for settings");
     return;
   }
 
   aInfo->upperLimit() = (tuner.rangehigh * 625) / 10000;
   aInfo->lowerLimit() = (tuner.rangelow * 625) / 10000;
 }
 
 void
 SetFMRadioFrequency(const uint32_t frequency)
 {
   struct v4l2_frequency freq = {0};
   freq.type = V4L2_TUNER_RADIO;
   freq.frequency = (frequency * 10000) / 625;
 
   int rc = ioctl(sRadioFD, VIDIOC_S_FREQUENCY, &freq);
   if (rc < 0)
-    HAL_LOG(("Could not set radio frequency"));
+    HAL_LOG("Could not set radio frequency");
 
   if (sMsmFMMode && rc >= 0)
     return;
 
   NS_DispatchToMainThread(new RadioUpdate(hal::FM_RADIO_OPERATION_TUNE,
                                           rc < 0 ?
                                           hal::FM_RADIO_OPERATION_STATUS_FAIL :
                                           hal::FM_RADIO_OPERATION_STATUS_SUCCESS));
@@ -458,17 +459,17 @@ uint32_t
 GetFMRadioFrequency()
 {
   if (!sRadioEnabled)
     return 0;
 
   struct v4l2_frequency freq;
   int rc = ioctl(sRadioFD, VIDIOC_G_FREQUENCY, &freq);
   if (rc < 0) {
-    HAL_LOG(("Could not get radio frequency"));
+    HAL_LOG("Could not get radio frequency");
     return 0;
   }
 
   return (freq.frequency * 625) / 10000;
 }
 
 bool
 IsFMRadioOn()
@@ -477,17 +478,17 @@ IsFMRadioOn()
 }
 
 uint32_t
 GetFMRadioSignalStrength()
 {
   struct v4l2_tuner tuner = {0};
   int rc = ioctl(sRadioFD, VIDIOC_G_TUNER, &tuner);
   if (rc < 0) {
-    HAL_LOG(("Could not query fm radio for signal strength"));
+    HAL_LOG("Could not query fm radio for signal strength");
     return 0;
   }
 
   return tuner.signal;
 }
 
 void
 CancelFMRadioSeek()
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -40,16 +40,17 @@
 #include "hardware_legacy/power.h"
 #include "libdisplay/GonkDisplay.h"
 #include "utils/threads.h"
 
 #include "base/message_loop.h"
 
 #include "Hal.h"
 #include "HalImpl.h"
+#include "HalLog.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/dom/battery/Constants.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/Preferences.h"
@@ -513,17 +514,17 @@ GetCurrentBatteryCharge(int* aCharge)
   bool success = ReadSysFile("/sys/class/power_supply/battery/capacity",
                              aCharge);
   if (!success) {
     return false;
   }
 
   #ifdef DEBUG
   if ((*aCharge < 0) || (*aCharge > 100)) {
-    HAL_LOG(("charge level contains unknown value: %d", *aCharge));
+    HAL_LOG("charge level contains unknown value: %d", *aCharge);
   }
   #endif
 
   return (*aCharge >= 0) && (*aCharge <= 100);
 }
 
 static bool
 GetCurrentBatteryCharging(int* aCharging)
@@ -538,17 +539,17 @@ GetCurrentBatteryCharging(int* aCharging
   bool success =
     ReadSysFile("/sys/class/power_supply/battery/charging_source", &chargingSrc);
 
   if (success) {
     #ifdef DEBUG
     if (chargingSrc != BATTERY_NOT_CHARGING &&
         chargingSrc != BATTERY_CHARGING_USB &&
         chargingSrc != BATTERY_CHARGING_AC) {
-      HAL_LOG(("charging_source contained unknown value: %d", chargingSrc));
+      HAL_LOG("charging_source contained unknown value: %d", chargingSrc);
     }
     #endif
 
     *aCharging = (chargingSrc == BATTERY_CHARGING_USB ||
                   chargingSrc == BATTERY_CHARGING_AC);
     return true;
   }
 
@@ -602,41 +603,41 @@ const char *wakeLockFilename = "/sys/pow
 const char *wakeUnlockFilename = "/sys/power/wake_unlock";
 
 template<ssize_t n>
 bool ReadFromFile(const char *filename, char (&buf)[n])
 {
   int fd = open(filename, O_RDONLY);
   ScopedClose autoClose(fd);
   if (fd < 0) {
-    HAL_LOG(("Unable to open file %s.", filename));
+    HAL_LOG("Unable to open file %s.", filename);
     return false;
   }
 
   ssize_t numRead = read(fd, buf, n);
   if (numRead < 0) {
-    HAL_LOG(("Error reading from file %s.", filename));
+    HAL_LOG("Error reading from file %s.", filename);
     return false;
   }
 
   buf[std::min(numRead, n - 1)] = '\0';
   return true;
 }
 
 bool WriteToFile(const char *filename, const char *toWrite)
 {
   int fd = open(filename, O_WRONLY);
   ScopedClose autoClose(fd);
   if (fd < 0) {
-    HAL_LOG(("Unable to open file %s.", filename));
+    HAL_LOG("Unable to open file %s.", filename);
     return false;
   }
 
   if (write(fd, toWrite, strlen(toWrite)) < 0) {
-    HAL_LOG(("Unable to write to file %s.", filename));
+    HAL_LOG("Unable to write to file %s.", filename);
     return false;
   }
 
   return true;
 }
 
 // We can write to screenEnabledFilename to enable/disable the screen, but when
 // we read, we always get "mem"!  So we have to keep track ourselves whether
@@ -714,18 +715,17 @@ GetScreenBrightness()
 }
 
 void
 SetScreenBrightness(double brightness)
 {
   // Don't use De Morgan's law to push the ! into this expression; we want to
   // catch NaN too.
   if (!(0 <= brightness && brightness <= 1)) {
-    HAL_LOG(("SetScreenBrightness: Dropping illegal brightness %f.",
-             brightness));
+    HAL_LOG("SetScreenBrightness: Dropping illegal brightness %f.", brightness);
     return;
   }
 
   // Convert the value in [0, 1] to an int between 0 and 255 and convert to a color
   // note that the high byte is FF, corresponding to the alpha channel.
   uint32_t val = static_cast<int>(round(brightness * 255.0));
   uint32_t color = (0xff<<24) + (val<<16) + (val<<8) + val;
 
@@ -804,22 +804,22 @@ AdjustSystemClock(int64_t aDeltaMillisec
     now.tv_sec -= 1;
   }
 
   do {
     fd = open("/dev/alarm", O_RDWR);
   } while (fd == -1 && errno == EINTR);
   ScopedClose autoClose(fd);
   if (fd < 0) {
-    HAL_LOG(("Failed to open /dev/alarm: %s", strerror(errno)));
+    HAL_LOG("Failed to open /dev/alarm: %s", strerror(errno));
     return;
   }
 
   if (ioctl(fd, ANDROID_ALARM_SET_RTC, &now) < 0) {
-    HAL_LOG(("ANDROID_ALARM_SET_RTC failed: %s", strerror(errno)));
+    HAL_LOG("ANDROID_ALARM_SET_RTC failed: %s", strerror(errno));
   }
 
   hal::NotifySystemClockChange(aDeltaMilliseconds);
 }
 
 int32_t
 GetTimezoneOffset()
 {
@@ -1035,45 +1035,45 @@ WaitForAlarm(void* aData)
 
 bool
 EnableAlarm()
 {
   MOZ_ASSERT(!sAlarmData);
 
   int alarmFd = open("/dev/alarm", O_RDWR);
   if (alarmFd < 0) {
-    HAL_LOG(("Failed to open alarm device: %s.", strerror(errno)));
+    HAL_LOG("Failed to open alarm device: %s.", strerror(errno));
     return false;
   }
 
   nsAutoPtr<AlarmData> alarmData(new AlarmData(alarmFd));
 
   struct sigaction actions;
   memset(&actions, 0, sizeof(actions));
   sigemptyset(&actions.sa_mask);
   actions.sa_flags = 0;
   actions.sa_handler = ShutDownAlarm;
   if (sigaction(SIGUSR1, &actions, nullptr)) {
-    HAL_LOG(("Failed to set SIGUSR1 signal for alarm-watcher thread."));
+    HAL_LOG("Failed to set SIGUSR1 signal for alarm-watcher thread.");
     return false;
   }
 
   pthread_attr_t attr;
   pthread_attr_init(&attr);
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 
   // Initialize the monitor for internally locking CPU to ensure thread-safe
   // before running the alarm-watcher thread.
   sInternalLockCpuMonitor = new Monitor("sInternalLockCpuMonitor");
   int status = pthread_create(&sAlarmFireWatcherThread, &attr, WaitForAlarm,
                               alarmData.get());
   if (status) {
     alarmData = nullptr;
     delete sInternalLockCpuMonitor;
-    HAL_LOG(("Failed to create alarm-watcher thread. Status: %d.", status));
+    HAL_LOG("Failed to create alarm-watcher thread. Status: %d.", status);
     return false;
   }
 
   pthread_attr_destroy(&attr);
 
   // The thread owns this now.  We only hold a pointer.
   sAlarmData = alarmData.forget();
   return true;
@@ -1094,30 +1094,30 @@ DisableAlarm()
 
   delete sInternalLockCpuMonitor;
 }
 
 bool
 SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
 {
   if (!sAlarmData) {
-    HAL_LOG(("We should have enabled the alarm."));
+    HAL_LOG("We should have enabled the alarm.");
     return false;
   }
 
   struct timespec ts;
   ts.tv_sec = aSeconds;
   ts.tv_nsec = aNanoseconds;
 
   // Currently we only support RTC wakeup alarm type.
   const int result = ioctl(sAlarmData->mFd,
                            ANDROID_ALARM_SET(ANDROID_ALARM_RTC_WAKEUP), &ts);
 
   if (result < 0) {
-    HAL_LOG(("Unable to set alarm: %s.", strerror(errno)));
+    HAL_LOG("Unable to set alarm: %s.", strerror(errno));
     return false;
   }
 
   return true;
 }
 
 static int
 OomAdjOfOomScoreAdj(int aOomScoreAdj)
@@ -1289,17 +1289,17 @@ static void
 EnsureKernelLowMemKillerParamsSet()
 {
   static bool kernelLowMemKillerParamsSet;
   if (kernelLowMemKillerParamsSet) {
     return;
   }
   kernelLowMemKillerParamsSet = true;
 
-  HAL_LOG(("Setting kernel's low-mem killer parameters."));
+  HAL_LOG("Setting kernel's low-mem killer parameters.");
 
   // Set /sys/module/lowmemorykiller/parameters/{adj,minfree,notify_trigger}
   // according to our prefs.  These files let us tune when the kernel kills
   // processes when we're low on memory, and when it notifies us that we're
   // running low on available memory.
   //
   // adj and minfree are both comma-separated lists of integers.  If adj="A,B"
   // and minfree="X,Y", then the kernel will kill processes with oom_adj
@@ -1391,39 +1391,39 @@ EnsureKernelLowMemKillerParamsSet()
 }
 
 static void
 SetNiceForPid(int aPid, int aNice)
 {
   errno = 0;
   int origProcPriority = getpriority(PRIO_PROCESS, aPid);
   if (errno) {
-    HAL_LOG(("Unable to get nice for pid=%d; error %d.  SetNiceForPid bailing.",
-             aPid, errno));
+    HAL_LOG("Unable to get nice for pid=%d; error %d.  SetNiceForPid bailing.",
+            aPid, errno);
     return;
   }
 
   int rv = setpriority(PRIO_PROCESS, aPid, aNice);
   if (rv) {
-    HAL_LOG(("Unable to set nice for pid=%d; error %d.  SetNiceForPid bailing.",
-             aPid, errno));
+    HAL_LOG("Unable to set nice for pid=%d; error %d.  SetNiceForPid bailing.",
+            aPid, errno);
     return;
   }
 
   // On Linux, setpriority(aPid) modifies the priority only of the main
   // thread of that process.  We have to modify the priorities of all of the
   // process's threads as well, so iterate over all the threads and increase
   // each of their priorites by aNice - origProcPriority (and also ensure that
   // none of the tasks has a lower priority than the main thread).
   //
   // This is horribly racy.
 
   DIR* tasksDir = opendir(nsPrintfCString("/proc/%d/task/", aPid).get());
   if (!tasksDir) {
-    HAL_LOG(("Unable to open /proc/%d/task.  SetNiceForPid bailing.", aPid));
+    HAL_LOG("Unable to open /proc/%d/task.  SetNiceForPid bailing.", aPid);
     return;
   }
 
   // Be careful not to leak tasksDir; after this point, we must call closedir().
 
   while (struct dirent* de = readdir(tasksDir)) {
     char* endptr = nullptr;
     long tidlong = strtol(de->d_name, &endptr, /* base */ 10);
@@ -1446,19 +1446,19 @@ SetNiceForPid(int aPid, int aNice)
     if (schedPolicy == SCHED_FIFO || schedPolicy == SCHED_RR) {
       continue;
     }
 
     errno = 0;
     // Get and set the task's new priority.
     int origtaskpriority = getpriority(PRIO_PROCESS, tid);
     if (errno) {
-      HAL_LOG(("Unable to get nice for tid=%d (pid=%d); error %d.  This isn't "
-               "necessarily a problem; it could be a benign race condition.",
-               tid, aPid, errno));
+      HAL_LOG("Unable to get nice for tid=%d (pid=%d); error %d.  This isn't "
+              "necessarily a problem; it could be a benign race condition.",
+              tid, aPid, errno);
       continue;
     }
 
     int newtaskpriority =
       std::max(origtaskpriority - origProcPriority + aNice, aNice);
 
     // Do not reduce priority of threads already running at priorities greater
     // than normal.  These threads are likely special service threads that need
@@ -1466,37 +1466,37 @@ SetNiceForPid(int aPid, int aNice)
     if (newtaskpriority > origtaskpriority &&
         origtaskpriority < ANDROID_PRIORITY_NORMAL) {
       continue;
     }
 
     rv = setpriority(PRIO_PROCESS, tid, newtaskpriority);
 
     if (rv) {
-      HAL_LOG(("Unable to set nice for tid=%d (pid=%d); error %d.  This isn't "
-               "necessarily a problem; it could be a benign race condition.",
-               tid, aPid, errno));
+      HAL_LOG("Unable to set nice for tid=%d (pid=%d); error %d.  This isn't "
+              "necessarily a problem; it could be a benign race condition.",
+              tid, aPid, errno);
       continue;
     }
   }
 
-  HAL_LOG(("Changed nice for pid %d from %d to %d.",
-           aPid, origProcPriority, aNice));
+  HAL_LOG("Changed nice for pid %d from %d to %d.",
+          aPid, origProcPriority, aNice);
 
   closedir(tasksDir);
 }
 
 void
 SetProcessPriority(int aPid,
                    ProcessPriority aPriority,
                    ProcessCPUPriority aCPUPriority,
                    uint32_t aBackgroundLRU)
 {
-  HAL_LOG(("SetProcessPriority(pid=%d, priority=%d, cpuPriority=%d, LRU=%u)",
-           aPid, aPriority, aCPUPriority, aBackgroundLRU));
+  HAL_LOG("SetProcessPriority(pid=%d, priority=%d, cpuPriority=%d, LRU=%u)",
+          aPid, aPriority, aCPUPriority, aBackgroundLRU);
 
   // If this is the first time SetProcessPriority was called, set the kernel's
   // OOM parameters according to our prefs.
   //
   // We could/should do this on startup instead of waiting for the first
   // SetProcessPriorityCall.  But in practice, the master process needs to set
   // its priority early in the game, so we can reasonably rely on
   // SetProcessPriority being called early in startup.
@@ -1508,59 +1508,59 @@ SetProcessPriority(int aPid,
     ProcessPriorityToString(aPriority)).get(), &oomScoreAdj);
 
   RoundOomScoreAdjUpWithBackroundLRU(oomScoreAdj, aBackgroundLRU);
 
   if (NS_SUCCEEDED(rv)) {
     int clampedOomScoreAdj = clamped<int>(oomScoreAdj, OOM_SCORE_ADJ_MIN,
                                                        OOM_SCORE_ADJ_MAX);
     if(clampedOomScoreAdj != oomScoreAdj) {
-      HAL_LOG(("Clamping OOM adjustment for pid %d to %d", aPid,
-               clampedOomScoreAdj));
+      HAL_LOG("Clamping OOM adjustment for pid %d to %d", aPid,
+              clampedOomScoreAdj);
     } else {
-      HAL_LOG(("Setting OOM adjustment for pid %d to %d", aPid,
-               clampedOomScoreAdj));
+      HAL_LOG("Setting OOM adjustment for pid %d to %d", aPid,
+              clampedOomScoreAdj);
     }
 
     // We try the newer interface first, and fall back to the older interface
     // on failure.
 
     if (!WriteToFile(nsPrintfCString("/proc/%d/oom_score_adj", aPid).get(),
                      nsPrintfCString("%d", clampedOomScoreAdj).get()))
     {
       int oomAdj = OomAdjOfOomScoreAdj(clampedOomScoreAdj);
 
       WriteToFile(nsPrintfCString("/proc/%d/oom_adj", aPid).get(),
                   nsPrintfCString("%d", oomAdj).get());
     }
   } else {
-    HAL_ERR(("Unable to read oom_score_adj pref for priority %s; "
-             "are the prefs messed up?", ProcessPriorityToString(aPriority)));
+    HAL_ERR("Unable to read oom_score_adj pref for priority %s; "
+            "are the prefs messed up?", ProcessPriorityToString(aPriority));
     MOZ_ASSERT(false);
   }
 
   int32_t nice = 0;
 
   if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
     rv = Preferences::GetInt(
       nsPrintfCString("hal.processPriorityManager.gonk.%s.Nice",
                       ProcessPriorityToString(aPriority)).get(),
       &nice);
   } else if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
     rv = Preferences::GetInt("hal.processPriorityManager.gonk.LowCPUNice",
                              &nice);
   } else {
-    HAL_ERR(("Unable to read niceness pref for priority %s; "
-             "are the prefs messed up?", ProcessPriorityToString(aPriority)));
+    HAL_ERR("Unable to read niceness pref for priority %s; "
+            "are the prefs messed up?", ProcessPriorityToString(aPriority));
     MOZ_ASSERT(false);
     rv = NS_ERROR_FAILURE;
   }
 
   if (NS_SUCCEEDED(rv)) {
-    HAL_LOG(("Setting nice for pid %d to %d", aPid, nice));
+    HAL_LOG("Setting nice for pid %d to %d", aPid, nice);
     SetNiceForPid(aPid, nice);
   }
 }
 
 static bool
 IsValidRealTimePriority(int aValue, int aSchedulePolicy)
 {
   return (aValue >= sched_get_priority_min(aSchedulePolicy)) &&
@@ -1568,48 +1568,48 @@ IsValidRealTimePriority(int aValue, int 
 }
 
 static void
 SetThreadNiceValue(pid_t aTid, ThreadPriority aThreadPriority, int aValue)
 {
   MOZ_ASSERT(aThreadPriority < NUM_THREAD_PRIORITY);
   MOZ_ASSERT(aThreadPriority >= 0);
 
-  HAL_LOG(("Setting thread %d to priority level %s; nice level %d",
-           aTid, ThreadPriorityToString(aThreadPriority), aValue));
+  HAL_LOG("Setting thread %d to priority level %s; nice level %d",
+          aTid, ThreadPriorityToString(aThreadPriority), aValue);
   int rv = setpriority(PRIO_PROCESS, aTid, aValue);
 
   if (rv) {
-    HAL_LOG(("Failed to set thread %d to priority level %s; error %s", aTid,
-             ThreadPriorityToString(aThreadPriority), strerror(errno)));
+    HAL_LOG("Failed to set thread %d to priority level %s; error %s", aTid,
+            ThreadPriorityToString(aThreadPriority), strerror(errno));
   }
 }
 
 static void
 SetRealTimeThreadPriority(pid_t aTid,
                           ThreadPriority aThreadPriority,
                           int aValue)
 {
   int policy = SCHED_FIFO;
 
   MOZ_ASSERT(aThreadPriority < NUM_THREAD_PRIORITY);
   MOZ_ASSERT(aThreadPriority >= 0);
   MOZ_ASSERT(IsValidRealTimePriority(aValue, policy), "Invalid real time priority");
 
   // Setting real time priorities requires using sched_setscheduler
-  HAL_LOG(("Setting thread %d to priority level %s; Real Time priority %d, "
-           "Schedule FIFO", aTid, ThreadPriorityToString(aThreadPriority),
-           aValue));
+  HAL_LOG("Setting thread %d to priority level %s; Real Time priority %d, "
+          "Schedule FIFO", aTid, ThreadPriorityToString(aThreadPriority),
+          aValue);
   sched_param schedParam;
   schedParam.sched_priority = aValue;
   int rv = sched_setscheduler(aTid, policy, &schedParam);
 
   if (rv) {
-    HAL_LOG(("Failed to set thread %d to real time priority level %s; error %s",
-             aTid, ThreadPriorityToString(aThreadPriority), strerror(errno)));
+    HAL_LOG("Failed to set thread %d to real time priority level %s; error %s",
+            aTid, ThreadPriorityToString(aThreadPriority), strerror(errno));
   }
 }
 
 static void
 SetThreadPriority(pid_t aTid, hal::ThreadPriority aThreadPriority)
 {
   // See bug 999115, we can only read preferences on the main thread otherwise
   // we create a race condition in HAL
@@ -1617,18 +1617,18 @@ SetThreadPriority(pid_t aTid, hal::Threa
   MOZ_ASSERT(aThreadPriority >= 0);
 
   const char* threadPriorityStr;
   switch (aThreadPriority) {
     case THREAD_PRIORITY_COMPOSITOR:
       threadPriorityStr = ThreadPriorityToString(aThreadPriority);
       break;
     default:
-      HAL_ERR(("Unrecognized thread priority %d; Doing nothing",
-               aThreadPriority));
+      HAL_ERR("Unrecognized thread priority %d; Doing nothing",
+              aThreadPriority);
       return;
   }
 
   int realTimePriority = Preferences::GetInt(
     nsPrintfCString("hal.gonk.%s.rt_priority", threadPriorityStr).get());
 
   if (IsValidRealTimePriority(realTimePriority, SCHED_FIFO)) {
     SetRealTimeThreadPriority(aTid, aThreadPriority, realTimePriority);
@@ -1680,18 +1680,18 @@ SetCurrentThreadPriority(ThreadPriority 
     case THREAD_PRIORITY_COMPOSITOR: {
       pid_t threadId = gettid();
       nsCOMPtr<nsIRunnable> runnable =
         new SetThreadPriorityRunnable(threadId, aThreadPriority);
       NS_DispatchToMainThread(runnable);
       break;
     }
     default:
-      HAL_LOG(("Unrecognized thread priority %d; Doing nothing",
-               aThreadPriority));
+      HAL_LOG("Unrecognized thread priority %d; Doing nothing",
+              aThreadPriority);
       return;
   }
 }
 
 void
 FactoryReset(FactoryResetReason& aReason)
 {
   nsCOMPtr<nsIRecoveryService> recoveryService =
--- a/hal/gonk/GonkSensor.cpp
+++ b/hal/gonk/GonkSensor.cpp
@@ -18,29 +18,23 @@
 #include <stdio.h>
 
 #include "mozilla/DebugOnly.h"
 
 #include "base/basictypes.h"
 #include "base/thread.h"
 
 #include "Hal.h"
+#include "HalLog.h"
 #include "HalSensor.h"
 #include "hardware/sensors.h"
 #include "nsThreadUtils.h"
 
-#undef LOG
-
-#include <android/log.h>
-
 using namespace mozilla::hal;
 
-#define LOGE(args...)  __android_log_print(ANDROID_LOG_ERROR, "GonkSensor" , ## args)
-#define LOGW(args...)  __android_log_print(ANDROID_LOG_WARN, "GonkSensor" , ## args)
-
 namespace mozilla {
 
 // The value from SensorDevice.h (Android)
 #define DEFAULT_DEVICE_POLL_RATE 200000000 /*200ms*/
 // ProcessOrientation.cpp needs smaller poll rate to detect delay between
 // different orientation angles
 #define ACCELEROMETER_POLL_RATE 66667000 /*66.667ms*/
 
@@ -172,17 +166,17 @@ PollSensors()
   sensors_event_t buffer[numEventMax];
   const sensor_t* sensors;
   int size = sSensorModule->get_sensors_list(sSensorModule, &sensors);
 
   do {
     // didn't check sSensorDevice because already be done on creating pollingThread.
     int n = sSensorDevice->poll(sSensorDevice, buffer, numEventMax);
     if (n < 0) {
-      LOGE("Error polling for sensor data (err=%d)", n);
+      HAL_ERR("Error polling for sensor data (err=%d)", n);
       break;
     }
 
     for (int i = 0; i < n; ++i) {
       // FIXME: bug 802004, add proper support for the magnetic field sensor.
       if (buffer[i].type == SENSOR_TYPE_MAGNETIC_FIELD)
         continue;
 
@@ -201,17 +195,17 @@ PollSensors()
           if (sensors[index].handle == buffer[i].sensor) {
             break;
           }
         }
         if (index < size &&
             HardwareSensorToHalSensor(sensors[index].type) != SENSOR_UNKNOWN) {
           buffer[i].type = sensors[index].type;
         } else {
-          LOGW("Could not determine sensor type of event");
+          HAL_LOG("Could not determine sensor type of event");
           continue;
         }
       }
 
       NS_DispatchToMainThread(new SensorRunnable(buffer[i], sensors, size));
     }
   } while (true);
 }
@@ -259,24 +253,24 @@ SetSensorState(SensorType aSensor, bool 
 
 void
 EnableSensorNotifications(SensorType aSensor)
 {
   if (!sSensorModule) {
     hw_get_module(SENSORS_HARDWARE_MODULE_ID,
                        (hw_module_t const**)&sSensorModule);
     if (!sSensorModule) {
-      LOGE("Can't get sensor HAL module\n");
+      HAL_ERR("Can't get sensor HAL module\n");
       return;
     }
 
     sensors_open(&sSensorModule->common, &sSensorDevice);
     if (!sSensorDevice) {
       sSensorModule = nullptr;
-      LOGE("Can't get sensor poll device from module \n");
+      HAL_ERR("Can't get sensor poll device from module \n");
       return;
     }
 
     sensor_t const* sensors;
     int count = sSensorModule->get_sensors_list(sSensorModule, &sensors);
     for (size_t i=0 ; i<size_t(count) ; i++) {
       sSensorDevice->activate(sSensorDevice, sensors[i].handle, 0);
     }
--- a/hal/gonk/GonkSwitch.cpp
+++ b/hal/gonk/GonkSwitch.cpp
@@ -9,35 +9,33 @@
  *
  * 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.
  */
 
-#include <android/log.h>
 #include <fcntl.h>
 #include <sysutils/NetlinkEvent.h>
 
 #include "base/message_loop.h"
 
 #include "Hal.h"
+#include "HalLog.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/Monitor.h"
 #include "nsPrintfCString.h"
 #include "nsXULAppAPI.h"
 #include "nsThreadUtils.h"
 #include "UeventPoller.h"
 
 using namespace mozilla::hal;
 
-#define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "GonkSwitch" , ## args) 
-
 #define SWITCH_HEADSET_DEVPATH "/devices/virtual/switch/h2w"
 #define SWITCH_USB_DEVPATH_GB  "/devices/virtual/switch/usb_configuration"
 #define SWITCH_USB_DEVPATH_ICS "/devices/virtual/android_usb/android0"
 
 namespace mozilla {
 namespace hal_impl {
 /**
  * The uevent for a usb on GB insertion looks like:
@@ -105,17 +103,17 @@ protected:
     if (fd <= 0) {
       return;
     }
 
     ScopedClose autoClose(fd);
     char state[16];
     ssize_t bytesRead = read(fd, state, sizeof(state));
     if (bytesRead < 0) {
-      LOG("Read data from %s fails", statePath.get());
+      HAL_ERR("Read data from %s fails", statePath.get());
       return;
     }
 
     if (state[bytesRead - 1] == '\n') {
       bytesRead--;
     }
     
     state[bytesRead] = '\0';
--- a/hal/gonk/UeventPoller.cpp
+++ b/hal/gonk/UeventPoller.cpp
@@ -23,16 +23,17 @@
 #include <unistd.h>
 
 #include <arpa/inet.h>
 #include <linux/types.h>
 #include <linux/netlink.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
 
+#include "HalLog.h"
 #include "nsDebug.h"
 #include "base/message_loop.h"
 #include "mozilla/FileUtils.h"
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 #include "nsXULAppAPI.h"
 
 #include "UeventPoller.h"
@@ -128,17 +129,18 @@ NetlinkPoller::OpenSocket()
     }
 
     if (saddr.nl_pid == 0) {
       return false;
     }
 
     // Once there was any other place in the same process assigning saddr.nl_pid by
     // gettid(), we can detect it and print warning message.
-    printf_stderr("The netlink socket address saddr.nl_pid=%u is in use. Let the kernel re-assign.\n", saddr.nl_pid);
+    HAL_LOG("The netlink socket address saddr.nl_pid=%u is in use. "
+            "Let the kernel re-assign.\n", saddr.nl_pid);
     saddr.nl_pid = 0;
   } while (true);
 
   if (!mIOLoop->WatchFileDescriptor(mSocket.get(),
                                     true,
                                     MessageLoopForIO::WATCH_READ,
                                     &mReadWatcher,
                                     this)) {
--- a/hal/linux/UPowerClient.cpp
+++ b/hal/linux/UPowerClient.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include <mozilla/Hal.h>
+#include "Hal.h"
+#include "HalLog.h"
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 #include <mozilla/dom/battery/Constants.h>
 #include "nsAutoRef.h"
 
 /*
  * Helper that manages the destruction of glib objects as soon as they leave
  * the current scope.
@@ -181,17 +182,17 @@ UPowerClient::~UPowerClient()
 
 void
 UPowerClient::BeginListening()
 {
   GError* error = nullptr;
   mDBusConnection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
 
   if (!mDBusConnection) {
-    g_printerr("Failed to open connection to bus: %s\n", error->message);
+    HAL_LOG("Failed to open connection to bus: %s\n", error->message);
     g_error_free(error);
     return;
   }
 
   DBusConnection* dbusConnection =
     dbus_g_connection_get_connection(mDBusConnection);
 
   // Make sure we do not exit the entire program if DBus connection get lost.
@@ -272,17 +273,17 @@ UPowerClient::UpdateTrackedDeviceSync()
   if (mTrackedDeviceProxy) {
     g_object_unref(mTrackedDeviceProxy);
     mTrackedDeviceProxy = nullptr;
   }
 
   // If that fails, that likely means upower isn't installed.
   if (!dbus_g_proxy_call(mUPowerProxy, "EnumerateDevices", &error, G_TYPE_INVALID,
                          typeGPtrArray, &devices, G_TYPE_INVALID)) {
-    g_printerr ("Error: %s\n", error->message);
+    HAL_LOG("Error: %s\n", error->message);
     g_error_free(error);
     return;
   }
 
   /*
    * We are looking for the first device that is a battery.
    * TODO: we could try to combine more than one battery.
    */
@@ -345,17 +346,17 @@ UPowerClient::GetDevicePropertiesSync(DB
 {
   GError* error = nullptr;
   GHashTable* hashTable = nullptr;
   GType typeGHashTable = dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
                                             G_TYPE_VALUE);
   if (!dbus_g_proxy_call(aProxy, "GetAll", &error, G_TYPE_STRING,
                          "org.freedesktop.UPower.Device", G_TYPE_INVALID,
                          typeGHashTable, &hashTable, G_TYPE_INVALID)) {
-    g_printerr("Error: %s\n", error->message);
+    HAL_LOG("Error: %s\n", error->message);
     g_error_free(error);
     return nullptr;
   }
 
   return hashTable;
 }
 
 /* static */ void
@@ -363,17 +364,17 @@ UPowerClient::GetDevicePropertiesCallbac
                                           DBusGProxyCall* aCall, void* aData)
 {
   GError* error = nullptr;
   GHashTable* hashTable = nullptr;
   GType typeGHashTable = dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
                                              G_TYPE_VALUE);
   if (!dbus_g_proxy_end_call(aProxy, aCall, &error, typeGHashTable,
                              &hashTable, G_TYPE_INVALID)) {
-    g_printerr("Error: %s\n", error->message);
+    HAL_LOG("Error: %s\n", error->message);
     g_error_free(error);
   } else {
     sInstance->UpdateSavedInfo(hashTable);
     hal::NotifyBatteryChange(hal::BatteryInformation(sInstance->mLevel,
                                                      sInstance->mCharging,
                                                      sInstance->mRemainingTime));
     g_hash_table_unref(hashTable);
   }
--- a/hal/sandbox/SandboxHal.cpp
+++ b/hal/sandbox/SandboxHal.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=2 ts=8 et ft=cpp : */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "Hal.h"
+#include "HalLog.h"
 #include "mozilla/AppProcessChecker.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/hal_sandbox/PHalChild.h"
 #include "mozilla/hal_sandbox/PHalParent.h"
 #include "mozilla/dom/TabParent.h"
 #include "mozilla/dom/TabChild.h"
 #include "mozilla/dom/battery/Types.h"
@@ -42,29 +43,29 @@ Hal()
     sHal = ContentChild::GetSingleton()->SendPHalConstructor();
   }
   return sHal;
 }
 
 void
 Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id)
 {
-  HAL_LOG(("Vibrate: Sending to parent process."));
+  HAL_LOG("Vibrate: Sending to parent process.");
 
   AutoInfallibleTArray<uint32_t, 8> p(pattern);
 
   WindowIdentifier newID(id);
   newID.AppendProcessID();
   Hal()->SendVibrate(p, newID.AsArray(), TabChild::GetFrom(newID.GetWindow()));
 }
 
 void
 CancelVibrate(const WindowIdentifier &id)
 {
-  HAL_LOG(("CancelVibrate: Sending to parent process."));
+  HAL_LOG("CancelVibrate: Sending to parent process.");
 
   WindowIdentifier newID(id);
   newID.AppendProcessID();
   Hal()->SendCancelVibrate(newID.AsArray(), TabChild::GetFrom(newID.GetWindow()));
 }
 
 void
 EnableBatteryNotifications()