Commit 8b483f91 authored by Jim Nelson's avatar Jim Nelson

#340: Logging suppressed by default. Set environment variable SHOTWELL_LOG to...

#340: Logging suppressed by default.  Set environment variable SHOTWELL_LOG to see all, SHOTWELL_DEBUG, SHOTWELL_MESSAGE, etc. to see by level.
parent e0eaa97a
namespace Debug {
private bool info_enabled = false;
private bool debug_enabled = false;
private bool message_enabled = false;
private bool warning_enabled = false;
private bool critical_enabled = false;
public void init() {
if (Environment.get_variable("SHOTWELL_LOG") != null) {
info_enabled = true;
debug_enabled = true;
message_enabled = true;
warning_enabled = true;
critical_enabled = true;
} else {
info_enabled = (Environment.get_variable("SHOTWELL_INFO") != null);
debug_enabled = (Environment.get_variable("SHOTWELL_DEBUG") != null);
message_enabled = (Environment.get_variable("SHOTWELL_MESSAGE") != null);
warning_enabled = (Environment.get_variable("SHOTWELL_WARNING") != null);
critical_enabled = (Environment.get_variable("SHOTWELL_CRITICAL") != null);
}
Log.set_handler(null, LogLevelFlags.LEVEL_INFO, info_handler);
Log.set_handler(null, LogLevelFlags.LEVEL_DEBUG, debug_handler);
Log.set_handler(null, LogLevelFlags.LEVEL_MESSAGE, message_handler);
Log.set_handler(null, LogLevelFlags.LEVEL_WARNING, warning_handler);
Log.set_handler(null, LogLevelFlags.LEVEL_CRITICAL, critical_handler);
}
public void terminate() {
}
private void log(FileStream stream, string prefix, string message) {
stream.puts(prefix);
stream.puts(message);
stream.putc('\n');
stream.flush();
}
private void info_handler(string? domain, LogLevelFlags flags, string message) {
if (info_enabled)
log(stdout, "[INF] ", message);
}
private void debug_handler(string? domain, LogLevelFlags flags, string message) {
if (debug_enabled)
log(stdout, "[DBG] ", message);
}
private void message_handler(string? domain, LogLevelFlags flags, string message) {
if (message_enabled)
log(stderr, "[MSG] ", message);
}
private void warning_handler(string? domain, LogLevelFlags flags, string message) {
if (warning_enabled)
log(stderr, "[WRN] ", message);
}
private void critical_handler(string? domain, LogLevelFlags flags, string message) {
if (critical_enabled)
log(stderr, "[CRT] ", message);
}
}
......@@ -40,7 +40,8 @@ SRC_FILES = \
util.vala \
BatchImport.vala \
ExportDialog.vala \
Resources.vala
Resources.vala \
Debug.vala
VAPI_FILES = \
libexif.vapi \
......
......@@ -29,6 +29,9 @@ void main(string[] args) {
// init GTK
Gtk.init(ref args);
// init debug prior to anything else
Debug.init();
// set up GLib environment
GLib.Environment.set_application_name(AppWindow.TITLE);
......@@ -56,6 +59,8 @@ void main(string[] args) {
shotwell.send_message((int) Unique.Command.ACTIVATE, null);
Debug.terminate();
return;
}
......@@ -95,5 +100,6 @@ void main(string[] args) {
DatabaseTable.terminate();
Resources.terminate();
AppWindow.terminate();
Debug.terminate();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment