From 717749a2c0776d22ada8b0f2170e3864c04ea27c Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Tue, 27 Jun 2017 21:57:35 +0200 Subject: [PATCH] mconnect: move logging to separate file --- src/mconnect/application.vala | 2 +- src/mconnect/devicechannel.vala | 2 +- src/mconnect/logging.vala | 46 +++++++++++++++++++++++++++++++++ src/mconnect/utils.vala | 21 --------------- 4 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 src/mconnect/logging.vala diff --git a/src/mconnect/application.vala b/src/mconnect/application.vala index 498c19f..bde4d52 100644 --- a/src/mconnect/application.vala +++ b/src/mconnect/application.vala @@ -56,7 +56,7 @@ namespace Mconn { Environment.set_variable("G_MESSAGES_DEBUG", "all", false); if (log_debug_verbose == true) - enable_vdebug(); + Logging.enable_vdebug(); core = Core.instance(); if (core == null) diff --git a/src/mconnect/devicechannel.vala b/src/mconnect/devicechannel.vala index dd85cb7..98ca502 100644 --- a/src/mconnect/devicechannel.vala +++ b/src/mconnect/devicechannel.vala @@ -161,7 +161,7 @@ class DeviceChannel : Object { this.peer_certificate = peer_cert; if (expected_peer != null) { - if (DebugLog.Verbose) { + if (Logging.VERBOSE) { vdebug("verify certificate, expecting: %s, got: %s", expected_peer.certificate_pem, peer_cert.certificate_pem); diff --git a/src/mconnect/logging.vala b/src/mconnect/logging.vala new file mode 100644 index 0000000..cdd9791 --- /dev/null +++ b/src/mconnect/logging.vala @@ -0,0 +1,46 @@ +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * AUTHORS + * Maciek Borzecki + */ + +namespace Logging { + + public bool VERBOSE = false; + +/** + * enable_vdebug: + * + * Enable verbose debug logging + */ +void enable_vdebug() { + VERBOSE = true; +} + +} + +/** + * vdebug: + * @format: format string + * + * Same as debug() but looks at verbose debug flag + */ +void vdebug(string format, ...) { + if (Logging.VERBOSE == true) { + var l = va_list(); + logv(null, LogLevelFlags.LEVEL_DEBUG, format, l); + } +} + diff --git a/src/mconnect/utils.vala b/src/mconnect/utils.vala index b3d14c5..d59e292 100644 --- a/src/mconnect/utils.vala +++ b/src/mconnect/utils.vala @@ -19,27 +19,6 @@ */ using Posix; -namespace DebugLog{ - public bool Verbose = false; -} - -void enable_vdebug() { - DebugLog.Verbose = true; -} - -/** - * vdebug: - * @format: format string - * - * Same as debug() but looks at verbose debug flag - */ -void vdebug(string format, ...) { - if (DebugLog.Verbose == true) { - var l = va_list(); - logv(null, LogLevelFlags.LEVEL_DEBUG, format, l); - } -} - /** * make_unique_device_string: * @id: device ID