Exemplo n.º 1
0
        public void Text(int level, ILogTarget target, string text)
        {
            string[] lines = text.Split('\n');
            var      last  = lines.Length - 1;

            if (last == 0)
            {
                target.Log(m_ti, new LogMsg(LogType.Info, LogOpt.Join, level,
                                            m_job.HierarchyLevel * m_indent, lines[0], -2));
            }
            else
            {
                for (int i = 0; i < last; i++)
                {
                    target.Log(m_ti, new LogMsg(LogType.Info, LogOpt.Join | LogOpt.EndLine, level,
                                                m_job.HierarchyLevel * m_indent, lines[i]));
                }
                if (lines[last].Length > 0)
                {
                    target.Log(m_ti, new LogMsg(LogType.Info, LogOpt.Join, level,
                                                m_job.HierarchyLevel * m_indent, lines[last]));
                }
            }
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 0; i < reporterArray.Length; i++)
                {
                    reporterArray[i].Text(m_ti, level, target, text);
                }
            }
        }
Exemplo n.º 2
0
        private void LogMessage(LogMessage logMessage)
        {
            logMessage.Format();

            if (logMessage.IsException)
            {
                _logTarget.Log(LogLevel.Error, logMessage.LoggerMessage, logMessage.Exception);
            }
            else
            {
                _logTarget.Log(LogLevel.Error, logMessage.LoggerMessage);
            }
        }
Exemplo n.º 3
0
        public void Progress(int level, ILogTarget target, double progress, bool relative = false)
        {
            if (relative)
            {
                progress += m_job.Progress;
            }
            if (progress > 1.0)
            {
                progress = 1.0;
            }
            m_job.Progress = progress;
            double seconds; string text; LogOpt opt;

            if (m_job.Timer == null)
            {
                seconds = -1.0; opt = LogOpt.None;
                text    = String.Format(CultureInfo.InvariantCulture, "{0,6:F2}%", 100.0 * progress);
            }
            else
            {
                seconds = m_job.Timer.ElapsedMilliseconds * 0.001; opt = LogOpt.Timed;
                text    = String.Format(CultureInfo.InvariantCulture, "{0,6:F2}% {1,10:F3} s", 100.0 * progress, seconds);
            }
            target.Log(m_ti, new LogMsg(LogType.Progress, opt, level,
                                        (m_job.HierarchyLevel - 1) * m_indent, m_job.Message, -2, text));
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 0; i < reporterArray.Length; i++)
                {
                    reporterArray[i].Progress(m_ti, level, target, m_job.Message, progress, seconds);
                }
            }
        }
Exemplo n.º 4
0
        public ReportJob Begin(ReportJob parentJob, int level, ILogTarget target, string text, bool timed, bool noLog = false)
        {
            if (parentJob == null)
            {
                parentJob = m_job;
            }
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 0; i < reporterArray.Length; i++)
                {
                    reporterArray[i].Begin(m_ti, level, target, text, timed);
                }
            }
            var opt = timed ? LogOpt.Timed : LogOpt.None;

            if (!noLog)
            {
                target.Log(m_ti, new LogMsg(LogType.Begin, opt, level, parentJob.HierarchyLevel * m_indent, text, -2));
            }
            m_jobStack.Push(m_job);
            m_job = new ReportJob(text, level, timed, parentJob);
            return(m_job);
        }
Exemplo n.º 5
0
        public AsyncLogTargetWrapper(ILogTarget target, int queueLimit, AsyncLogTargetOverflowAction overflowAction)
        {
            _target          = target;
            _messageQueue    = new BlockingCollection <LogEventArgs>(queueLimit);
            _overflowTimeout = overflowAction == AsyncLogTargetOverflowAction.Block ? -1 : 0;

            _messageThread = new Thread(() => {
                while (!_messageQueue.IsCompleted)
                {
                    try
                    {
                        _target.Log(this, _messageQueue.Take());
                    }
                    catch (InvalidOperationException)
                    {
                        // IOE means that Take() was called on a completed collection.
                        // Some other thread can call CompleteAdding after we pass the
                        // IsCompleted check but before we call Take.
                        // We can simply catch the exception since the loop will break
                        // on the next iteration.
                    }
                }
            });

            _messageThread.IsBackground = true;
            _messageThread.Start();
        }
Exemplo n.º 6
0
 public void Log(int threadIndex, LogMsg msg)
 {
     if (m_filterFun(msg))
     {
         m_target.Log(threadIndex, msg);
     }
 }
Exemplo n.º 7
0
        public void Line(LogType type, int level, ILogTarget target, string t0, int p1 = 0, string t1 = null)
        {
            target.Log(m_ti, new LogMsg(type, LogOpt.EndLine, level, m_job.HierarchyLevel * m_indent, t0, p1, t1));
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 0; i < reporterArray.Length; i++)
                {
                    reporterArray[i].Line(m_ti, type, level, target, t0, p1, t1);
                }
            }
        }
Exemplo n.º 8
0
        public void Wrap(int level, ILogTarget target, string text)
        {
            target.Log(m_ti, new LogMsg(LogType.Info, LogOpt.Join | LogOpt.Wrap, level,
                                        m_job.HierarchyLevel * m_indent, text, -2));
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 0; i < reporterArray.Length; i++)
                {
                    reporterArray[i].Wrap(m_ti, level, target, text);
                }
            }
        }
Exemplo n.º 9
0
        public void Values(int level, ILogTarget target, string name, string separator, object[] values)
        {
            var text = values.Length == 1 ? values[0].ToString() : values.Map(o => o.ToString()).Join(separator);

            target.Log(m_ti, new LogMsg(LogType.Info, LogOpt.EndLine, level,
                                        m_job.HierarchyLevel * m_indent, name, 40, text));
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 0; i < reporterArray.Length; i++)
                {
                    reporterArray[i].Values(m_ti, level, target, name, separator, values);
                }
            }
        }
Exemplo n.º 10
0
        public double End(int level, ILogTarget target, string text, bool addTimeToParent)
        {
            var    parentJob = m_job.ParentJob;
            double seconds; string time; LogOpt opt;

            if (m_job.Timer != null)
            {
                seconds = m_job.Timer.ElapsedMilliseconds * 0.001; opt = LogOpt.EndLine | LogOpt.Timed;
                time    = String.Format(CultureInfo.InvariantCulture, "{0:F3} s", seconds);
            }
            else
            {
                seconds = 0.0; time = null; opt = LogOpt.EndLine;
            }
            m_job.Disposed = true;
            if (level != m_job.Level)
            {
                Report.Warn("Report.Begin({0}) level different from Report.End({1}),"
                            + " using Report.End({0})", m_job.Level, level);
                level = m_job.Level;
            }
            var beginText = m_job.Message;

            if (text == null)
            {
                text = beginText;
            }
            else if (text != beginText)
            {
                text = beginText + text; opt |= LogOpt.NewText;
            }
            if (m_job.ReportTests == true)
            {
                var testInfo = m_job.TestInfo;
                if (m_jobStack.Count > 0)
                {
                    m_job = m_jobStack.Pop(); m_job.TestInfo += testInfo;
                }
                else
                {
                    Report.Warn("superfluous Report.End() encountered");
                }
                var passed = String.Format(CultureInfo.InvariantCulture,
                                           "[{0}/{1} OK]", testInfo.PassedCount, testInfo.TestCount);
                time = time != null ? passed + ' ' + time : passed;
                target.Log(m_ti, new LogMsg(LogType.End, opt, level, parentJob.HierarchyLevel * m_indent,
                                            text, -2, time));
                if (testInfo.FailedCount > 0)
                {
                    var failed = String.Format(CultureInfo.InvariantCulture,
                                               " {0}/{1} FAILED", testInfo.FailedCount, testInfo.TestCount);
                    target.Log(m_ti, new LogMsg(LogType.Warn, opt, level, parentJob.HierarchyLevel * m_indent,
                                                "WARNING: " + text + failed));
                }
            }
            else
            {
                var childrenTime = m_job.ChildrenTime;
                if (seconds > 0.0 && childrenTime > 0.0)
                {
                    time = String.Format(CultureInfo.InvariantCulture, "[{0:F2}x] ", childrenTime / seconds) + time;
                }
                if (addTimeToParent)
                {
                    lock (parentJob) parentJob.ChildrenTime += seconds;
                }
                if (m_jobStack.Count > 0)
                {
                    m_job = m_jobStack.Pop();
                }
                else
                {
                    Report.Warn("superfluous Report.End() encountered");
                }
                target.Log(m_ti, new LogMsg(LogType.End, opt, level, parentJob.HierarchyLevel * m_indent,
                                            text, -2, time));
            }
            var reporterArray = m_reporterArray;

            if (reporterArray != null)
            {
                for (int i = 1; i < reporterArray.Length; i++)
                {
                    reporterArray[i].End(m_ti, level, target, text, seconds);
                }
            }
            return(seconds);
        }
Exemplo n.º 11
0
        /*============================================================================*/
        /* Public Functions                                                           */
        /*============================================================================*/

        public void Debug(object message, params object[] messageParameters)
        {
            _target.Log(_source, LogLevel.DEBUG, DateTime.Now, message, messageParameters);
        }