Commit b4115309 authored by Jim Nelson's avatar Jim Nelson

#2078: Logging to file only occurs in library mode. Direct edit mode will still log to console if

SHOTWELL_LOG is set.
parent ba037dca
......@@ -10,11 +10,14 @@ class AppDirs {
private static File exec_dir;
private static File data_dir = null;
// Because this is called prior to Debug.init(), this function cannot do any logging calls
public static void init(string arg0) {
File exec_file = File.new_for_path(Environment.find_program_in_path(arg0));
exec_dir = exec_file.get_parent();
}
// Because this *may* be called prior to Debug.init(), this function cannot do any logging
// calls
public static void terminate() {
}
......
......@@ -9,9 +9,9 @@ namespace Debug {
LogLevelFlags.LEVEL_CRITICAL |
LogLevelFlags.LEVEL_WARNING |
LogLevelFlags.LEVEL_MESSAGE;
public const string VIEWER_PREFIX = "V";
public const string LIBRARY_PREFIX = "L";
public const string INIT_PREFIX = "I";
// Ideally, there would be a LogLevelFlags.NONE constant to use as
// empty value but failing that, 0 works as well
......@@ -24,10 +24,8 @@ namespace Debug {
private unowned FileStream log_err = null;
private FileStream log_file_stream = null;
public static void init() {
// Temporary prefix during initialisation, before we know whether
// the application is in Library or Viewer mode
log_app_version_prefix = INIT_PREFIX;
public static void init(string app_version_prefix) {
log_app_version_prefix = app_version_prefix;
// default to stdout/stderr if file cannot be opened or console is specified
log_out = stdout;
......@@ -35,7 +33,8 @@ namespace Debug {
string log_file_error_msg = null;
File log_file = AppDirs.get_log_file();
// logging to disk is currently off for viewer more; see http://trac.yorba.org/ticket/2078
File? log_file = (log_app_version_prefix == LIBRARY_PREFIX) ? AppDirs.get_log_file() : null;
if(log_file != null) {
File log_dir = log_file.get_parent();
try {
......@@ -100,10 +99,6 @@ namespace Debug {
public static void terminate() {
}
public static void set_app_version_prefix(string app_version_prefix) {
log_app_version_prefix = app_version_prefix;
}
private bool is_enabled(LogLevelFlags flag) {
return ((log_mask & flag) > 0);
}
......
......@@ -533,6 +533,7 @@ public class LibraryWindow : AppWindow {
}
}
// This may be called before Debug.init(), so no error logging may be made
public static bool is_mount_uri_supported(string uri) {
foreach (string scheme in SUPPORTED_MOUNT_SCHEMES) {
if (uri.has_prefix(scheme))
......
......@@ -41,8 +41,6 @@ void library_exec(string[] mounts) {
if (already_running())
return;
#else
// update Debug prefix
Debug.set_app_version_prefix(Debug.LIBRARY_PREFIX);
// the library is single-instance; editing windows are one-process-per
Unique.App shotwell = new Unique.App("org.yorba.shotwell", null);
shotwell.add_command("MOUNTED_CAMERA", (int) ShotwellCommand.MOUNTED_CAMERA);
......@@ -184,8 +182,6 @@ void library_exec(string[] mounts) {
}
void editing_exec(string filename) {
// update Debug prefix
Debug.set_app_version_prefix(Debug.VIEWER_PREFIX);
// init modules direct-editing relies on
DatabaseTable.init(null);
DirectPhoto.init();
......@@ -233,24 +229,9 @@ void main(string[] args) {
return;
}
// set custom data directory if it's been supplied
if (data_dir != null)
AppDirs.set_data_dir(File.parse_name(data_dir));
// Verify the private data directory before continuing
AppDirs.verify_data_dir();
// init internationalization with the default system locale
InternationalSupport.init(Resources.APP_GETTEXT_PACKAGE, args);
startup_timer = new Timer();
startup_timer.start();
// init debug prior to anything else (except Gtk, which it relies on)
Debug.init();
// set up GLib environment
GLib.Environment.set_application_name(Resources.APP_TITLE);
// init debug prior to anything else (except Gtk, which it relies on, and AppDirs, which needs
// to be set ASAP) ... since we need to know what mode we're in, examine the command-line
// first
// walk command-line arguments for camera mounts or filename for direct editing ... only one
// filename supported for now, so take the first one and drop the rest ... note that URIs for
......@@ -263,11 +244,29 @@ void main(string[] args) {
if (LibraryWindow.is_mount_uri_supported(arg)) {
mounts += arg;
} else if (filename == null && !arg.contains("://")) {
} else if (is_string_empty(filename) && !arg.contains("://")) {
filename = arg;
}
}
Debug.init(is_string_empty(filename) ? Debug.LIBRARY_PREFIX : Debug.VIEWER_PREFIX);
// set custom data directory if it's been supplied
if (data_dir != null)
AppDirs.set_data_dir(File.parse_name(data_dir));
// Verify the private data directory before continuing
AppDirs.verify_data_dir();
// init internationalization with the default system locale
InternationalSupport.init(Resources.APP_GETTEXT_PACKAGE, args);
startup_timer = new Timer();
startup_timer.start();
// set up GLib environment
GLib.Environment.set_application_name(Resources.APP_TITLE);
// in both the case of running as the library or an editor, Resources is always
// initialized
Resources.init();
......@@ -275,7 +274,7 @@ void main(string[] args) {
// since it's possible for a mount name to be passed that's not supported (and hence an empty
// mount list), or for nothing to be on the command-line at all, only go to direct editing if a
// filename is spec'd
if (filename == null)
if (is_string_empty(filename))
library_exec(mounts);
else
editing_exec(filename);
......
......@@ -18,15 +18,16 @@ int number_of_processors() {
#endif
#if WINDOWS
// Because this function is called prior to Debug.init(), it cannot make any logging calls
void win_init(File exec_dir) {
// On Windows we prepend the directory containing the Shotwell executable to the PATH.
// This is necessary so that the gconf-d executable (which lives in ../libexec) will
// be able to find the DLLs it needs, which are in the Shotwell executable directory.
string path = Environment.get_variable("PATH");
if (path == null)
error("can't get path");
print("can't get path\n");
if (!Environment.set_variable("PATH", exec_dir.get_path() + ";" + path, true))
error("can't set path");
print("can't set path\n");
}
// Return the directory in which Shotwell is installed, or null if uninstalled.
......
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