Merge: Use --log
authorJean Privat <jean@pryen.org>
Fri, 27 Feb 2015 02:51:36 +0000 (09:51 +0700)
committerJean Privat <jean@pryen.org>
Fri, 27 Feb 2015 02:51:36 +0000 (09:51 +0700)
Use the option --log to log things.

It is not that hard to add logged things and it helped me, in #1177, to track easily the bug in rta.

Pull-Request: #1178
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

share/man/nitc.md
src/rapid_type_analysis.nit
src/toolcontext.nit
tests/nitc.args
tests/sav/nitc_args9.res [new file with mode: 0644]

index 75da7c8..5daafeb 100644 (file)
@@ -115,11 +115,14 @@ See the documentation of these specific modules for details.
 
 `--log`
 :   Generate various log files.
-    Currently unused.
+
+    The tool will generate some files in the logging directory (see `--log-dir`).
+    These files are intended to the advanced user and the developers of the tools.
 
 `--log-dir`
 :   Directory where to generate log files.
-    Currently unused.
+
+    By default the directory is called `logs` in the working directory.
 
 
 `-h`, `-?`, `--help`
index 2d9fee4..f5c1dc2 100644 (file)
@@ -36,6 +36,13 @@ redef class ModelBuilder
        do
                var analysis = new RapidTypeAnalysis(self, mainmodule)
                analysis.run_analysis
+
+               if toolcontext.opt_log.value then
+                       var basename = toolcontext.log_directory / mainmodule.name
+                       analysis.live_methods_to_tree.write_to_file(basename + ".rta_methods.txt")
+                       analysis.live_types_to_csv.write_to_file(basename + ".rta_types.csv")
+               end
+
                return analysis
        end
 end
index a5b7ceb..62c184a 100644 (file)
@@ -102,6 +102,9 @@ class ToolContext
        # Directory where to generate log files
        var log_directory: String = "logs"
 
+       # Stream in `log_directory` where all info messages are written
+       var log_info: nullable Writer = null
+
        # Messages
        private var messages = new Array[Message]
        private var message_sorter: Comparator = default_comparator
@@ -236,6 +239,10 @@ class ToolContext
                if level <= verbose_level then
                        print "{s}"
                end
+               if log_info != null then
+                       log_info.write s
+                       log_info.write "\n"
+               end
        end
 
        # Executes a program while checking if it's available and if the execution ended correctly
@@ -429,8 +436,10 @@ The Nit language documentation and the source code of its tools and libraries ma
                if opt_log.value then
                        # Make sure the output directory exists
                        log_directory.mkdir
-               end
 
+                       # Redirect the verbose messages
+                       log_info = (log_directory/"info.txt").to_path.open_wo
+               end
        end
 
        # Get the current `nit_version` or "DUMMY_VERSION" if `--set-dummy-tool` is set.
index 6a47146..0d83b02 100644 (file)
@@ -6,3 +6,4 @@
 --separate ../examples/hello_world.nit -m test_mixin.nit -o out/nitgs-hello_world_mixed ; out/nitgs-hello_world_mixed
 base_simple_import.nit base_simple.nit --dir out/ ; out/base_simple ; out/base_simple_import
 test_define.nit -D text=hello -D num=42 -D flag --dir out/ ; out/test_define
+--log --log-dir $WRITE test_prog -o out/test_prog.bin
diff --git a/tests/sav/nitc_args9.res b/tests/sav/nitc_args9.res
new file mode 100644 (file)
index 0000000..f18fded
--- /dev/null
@@ -0,0 +1,3 @@
+info.txt
+test_prog.rta_methods.txt
+test_prog.rta_types.csv