[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Common / Logging / InternalTrace.cs
1 // ***********************************************************************
2 // Copyright (c) 2008-2013 Charlie Poole
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
23 #define PORTABLE
24 #define TIZEN
25 #define NUNIT_FRAMEWORK
26 #define NUNITLITE
27 #define NET_4_5
28 #define PARALLEL
29 using System;
30 using System.IO;
31
32 #if NUNIT_ENGINE
33 namespace NUnit.Engine.Internal
34 #elif NUNIT_FRAMEWORK
35 namespace NUnit.Framework.Internal
36 #else
37 namespace NUnit.Common
38 #endif
39 {
40     /// <summary>
41     /// InternalTrace provides facilities for tracing the execution
42     /// of the NUnit framework. Tests and classes under test may make use 
43     /// of Console writes, System.Diagnostics.Trace or various loggers and
44     /// NUnit itself traps and processes each of them. For that reason, a
45     /// separate internal trace is needed.
46     /// 
47     /// Note:
48     /// InternalTrace uses a global lock to allow multiple threads to write
49     /// trace messages. This can easily make it a bottleneck so it must be 
50     /// used sparingly. Keep the trace Level as low as possible and only
51     /// insert InternalTrace writes where they are needed.
52     /// TODO: add some buffering and a separate writer thread as an option.
53     /// TODO: figure out a way to turn on trace in specific classes only.
54     /// </summary>
55     public static class InternalTrace
56     {
57         private static InternalTraceLevel traceLevel;
58         private static InternalTraceWriter traceWriter;
59
60         /// <summary>
61         /// Gets a flag indicating whether the InternalTrace is initialized
62         /// </summary>
63         public static bool Initialized { get; private set; }
64
65 #if !PORTABLE
66         /// <summary>
67         /// Initialize the internal trace facility using the name of the log
68         /// to be written to and the trace level.
69         /// </summary>
70         /// <param name="logName">The log name</param>
71         /// <param name="level">The trace level</param>
72         public static void Initialize(string logName, InternalTraceLevel level)
73         {
74             if (!Initialized)
75             {
76                 traceLevel = level;
77
78                 if (traceWriter == null && traceLevel > InternalTraceLevel.Off)
79                 {
80                     traceWriter = new InternalTraceWriter(logName);
81                     traceWriter.WriteLine("InternalTrace: Initializing at level {0}", traceLevel);
82                 }
83
84                 Initialized = true;
85             }
86             else
87                 traceWriter.WriteLine("InternalTrace: Ignoring attempted re-initialization at level {0}", level);
88         }
89 #endif
90
91         /// <summary>
92         /// Initialize the internal trace using a provided TextWriter and level
93         /// </summary>
94         /// <param name="writer">A TextWriter</param>
95         /// <param name="level">The InternalTraceLevel</param>
96         public static void Initialize(TextWriter writer, InternalTraceLevel level)
97         {
98             if (!Initialized)
99             {
100                 traceLevel = level;
101
102                 if (traceWriter == null && traceLevel > InternalTraceLevel.Off)
103                 {
104                     traceWriter = new InternalTraceWriter(writer);
105                     traceWriter.WriteLine("InternalTrace: Initializing at level " + traceLevel.ToString());
106                 }
107
108                 Initialized = true;
109             }
110         }
111
112         /// <summary>
113         /// Get a named Logger
114         /// </summary>
115         /// <returns></returns>
116         public static Logger GetLogger(string name)
117         {
118             return new Logger(name, traceLevel, traceWriter);
119         }
120
121         /// <summary>
122         /// Get a logger named for a particular Type.
123         /// </summary>
124         public static Logger GetLogger(Type type)
125         {
126             return GetLogger(type.FullName);
127         }
128     }
129 }