about summary refs log tree commit diff
path: root/src/libmain/shared.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-03-22T20·53+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-03-22T20·53+0000
commit777e13b94b2da466c16a5836b52413aa9d246cd5 (patch)
tree2d00fc590710fa8ecddaeda01f29db922266bb56 /src/libmain/shared.cc
parent79bb0008ec9afa8d8cee9e6b807a579bcb1c92ab (diff)
* Nix now has three different formats for the log information it
  writes to stderr:
  
  - `pretty': the old nested style (default)
  - `escapes': uses escape codes to indicate nesting and message
    level; can be processed using `log2xml'
  - `flat': just plain text, no nesting

  These can be set using `--log-type TYPE' or the NIX_LOG_TYPE
  environment variable.  

Diffstat (limited to 'src/libmain/shared.cc')
-rw-r--r--src/libmain/shared.cc19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index ec639052b5..a93d6cb501 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -18,6 +18,15 @@ void sigintHandler(int signo)
 }
 
 
+void setLogType(string lt)
+{
+    if (lt == "pretty") logType = ltPretty;
+    else if (lt == "escapes") logType = ltEscapes;
+    else if (lt == "flat") logType = ltFlat;
+    else throw UsageError("unknown log type");
+}
+
+
 /* Initialize and reorder arguments, then call the actual argument
    processor. */
 static void initAndRun(int argc, char * * argv)
@@ -44,6 +53,10 @@ static void initAndRun(int argc, char * * argv)
     if (sigaction(SIGINT, &act, &oact))
         throw SysError("installing handler for SIGINT");
 
+    /* Process the NIX_LOG_TYPE environment variable. */
+    char * lt = getenv("NIX_LOG_TYPE");
+    if (lt) setLogType(lt);
+
     /* Put the arguments in a vector. */
     Strings args, remaining;
     while (argc--) args.push_back(*argv++);
@@ -72,7 +85,11 @@ static void initAndRun(int argc, char * * argv)
         string arg = *i;
         if (arg == "--verbose" || arg == "-v")
             verbosity = (Verbosity) ((int) verbosity + 1);
-        else if (arg == "--build-output" || arg == "-B")
+        else if (arg == "--log-type") {
+            ++i;
+            if (i == args.end()) throw UsageError("`--log-type' requires an argument");
+            setLogType(*i);
+        } else if (arg == "--build-output" || arg == "-B")
             buildVerbosity = lvlError; /* lowest */
         else if (arg == "--help") {
             printHelp();