diff --git a/src/orca/orca.py b/src/orca/orca.py
index ac300e4..1f5c7bb 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -1581,6 +1581,7 @@ def main():
         # t is for text setup
         # v is for version
         #
+        debugFileName = ""
         opts, args = getopt.getopt(
             arglist,
             "?stnvld:e:u:",
@@ -1593,6 +1594,8 @@ def main():
              "text-setup",
              "no-setup",
              "list-apps",
+             "debug",
+             "debug-file=",
              "version"])
         for opt, val in opts:
             if opt in ("-u", "--user-prefs-dir"):
@@ -1650,6 +1653,12 @@ def main():
             if opt in ("-v", "--version"):
                 print "Orca %s" % platform.version
                 die(0)
+            if opt == "--debug":
+                debug.debugLevel = debug.LEVEL_ALL
+                debug.eventDebugLevel = debug.LEVEL_OFF
+                debugFileName = time.strftime('debug-%Y-%m-%d-%H:%M:%S.out')
+            if opt == "--debug-file":
+                debugFileName = val.strip()
             if opt in ("-l", "--list-apps"):
                 apps = filter(lambda x: x is not None,
                               pyatspi.Registry.getDesktop(0))
@@ -1662,6 +1671,9 @@ def main():
         usage()
         die(2)
 
+    if debugFileName != "":
+        debug.debugFile = open(debugFileName, 'w', 0)
+
     # Do not run Orca if accessibility has not been enabled.
     # We do allow, however, one to force Orca to run via the
     # "-n" switch.  The main reason is so that things such
