예제 #1
0
파일: TextBackend.cs 프로젝트: rte-se/emul8
        protected string FormatLogEntry(LogEntry entry)
        {
            var messageBuilder = new StringBuilder();
            var messages = entry.Message.Split('\n').GetEnumerator();
            messages.MoveNext();

            if(entry.ObjectName != null)
            {
                var currentEmulation = EmulationManager.Instance.CurrentEmulation;
                var machineCount = currentEmulation.MachinesCount;
                if(machineCount > 1 && entry.MachineName != null)
                {
                    messageBuilder.AppendFormat("{2}/{0}: {1}", entry.ObjectName, messages.Current, entry.MachineName);
                }
                else
                {
                    messageBuilder.AppendFormat("{0}: {1}", entry.ObjectName, messages.Current);
                }
            }
            else
            {
                messageBuilder.Append(messages.Current);
            }
            while(messages.MoveNext())
            {
                messageBuilder.Append(Environment.NewLine);
                messageBuilder.Append("    ");
                messageBuilder.Append(messages.Current);
            }
            return messageBuilder.ToString();
        }
예제 #2
0
파일: LogEntry.cs 프로젝트: rte-se/emul8
 public bool EqualsWithoutIdAndTime(LogEntry entry)
 {
     return entry != null &&
         numericLogLevel == entry.numericLogLevel &&
         ThreadId == entry.ThreadId &&
         SourceId == entry.SourceId &&
         Message == entry.Message;
 }
예제 #3
0
파일: FileBackend.cs 프로젝트: rte-se/emul8
        public override void Log(LogEntry entry)
        {
            if(!ShouldBeLogged(entry))
            {
                return;
            }

            lock(sync)
            {
                if(isDisposed)
                {
                    return;
                }

                var type = entry.Type;
                var message = FormatLogEntry(entry);
                output.WriteLine(string.Format("{0:HH:mm:ss} [{1}] {2}", CustomDateTime.Now, type, message));
            }
        }
예제 #4
0
파일: ListViewLog.cs 프로젝트: rte-se/emul8
        public int AddItem(LogEntry entry, bool scrollOnRefresh, int? limit = null)
        {
            int rowId;

            if(SqueezeEntries && entry.EqualsWithoutIdAndTime(lastLogEntry))
            {
                rowId = listStore.RowCount - 1;

                listStore.SetValue(rowId, idField, entry.Id);
                listStore.SetValue(rowId, textField, string.Format("{0} ({1})", entry.Message, ++lastLogEntryCounter));
                listStore.SetValue(rowId, timestampField, string.Format("{0:HH:mm:ss.ffff}", entry.Time));

                return rowId;
            }

            rowId = listStore.AddRow();

            listStore.SetValues(rowId, 
                imgField,       LogLevelToIcon(entry.Type),
                typeField,      entry.Type.ToString(),
                machineField,   entry.MachineName ?? string.Empty,
                objectField,    entry.ObjectName ?? string.Empty,
                textField,      entry.Message,
                timestampField, string.Format("{0:HH:mm:ss.ffff}", entry.Time),
                idField,        entry.Id);

            if(scrollOnRefresh || entry.Id == SelectedItemId)
            {
                SelectRow(rowId);
            }
            while (limit.HasValue && limit != 0 && listStore.RowCount > limit)
            {
                listStore.RemoveRow(0);
            }

            lastLogEntry = entry;
            lastLogEntryCounter = 1;
            return rowId;
        }
예제 #5
0
        public override void Log(LogEntry entry)
        {
            if(!ShouldBeLogged(entry))
            {
                return;
            }

            var type = entry.Type;
            var changeColor = ColoringEnabled && output == Console.Out && type.Color.HasValue && !isRedirected;
            var message = FormatLogEntry(entry);
            
            lock(syncObject)
            {
                if(changeColor)
                {
                    Console.ForegroundColor = type.Color.Value;
                }
                string line;
                if(LogThreadId && entry.ThreadId != null)
                {
                    line = string.Format("{0:HH:mm:ss.ffff} [{1}] ({3}) {2}", CustomDateTime.Now, type, message, entry.ThreadId);
                }
                else
                {
                    line = string.Format("{0:HH:mm:ss.ffff} [{1}] {2}", CustomDateTime.Now, type, message);
                }
                if(output == Console.Out && !ReportRepeatingLines && 
                   lastMessage == message && lastMessageLinesCount != -1 && lastType == type && !isRedirected)
                {
                    try
                    {
                        counter++;
                        Console.CursorVisible = false;
                        Console.CursorTop = Math.Max(0, Console.CursorTop - lastMessageLinesCount);
                        // it can happen that console is resized between one and other write
                        // in case console is widened it would not erase previous messages
                        var realLine = string.Format("{0} ({1})", line, counter);
                        var currentLinesCount = GetMessageLinesCount(realLine);
                        var lineDiff = Math.Max(0, lastMessageLinesCount - currentLinesCount);
                        var width = Console.WindowWidth;
                        
                        Console.WriteLine(realLine);
                        lineDiff.Times(() => Console.WriteLine(Enumerable.Repeat<char>(' ', width - 1).ToArray()));
                        Console.CursorVisible = true;
                        Console.CursorTop = Math.Max(0, Console.CursorTop - lineDiff);
                        lastMessageLinesCount = GetMessageLinesCount(realLine);
                    }
                    catch(ArgumentOutOfRangeException)
                    {
                        // console was resized during computations
                        Console.Clear();
                        WriteNewLine(line);
                    }
                }
                else
                {
                    WriteNewLine(line);
                    lastMessage = message;
                    lastType = type;
                }
                if(changeColor)
                {
                    Console.ResetColor();
                }
            }
        }
예제 #6
0
 public override void Log(LogEntry entry)
 {
     cache.Add(entry);
 }
예제 #7
0
            public LogEntry ToLogEntry(Document doc)
            {
                LogLevel ll;
                LogLevel.TryParse(doc.Get(TypeFiledName), out ll);

                var result = new LogEntry(DateTime.FromBinary(long.Parse(doc.Get(TimeFiledName))), ll, doc.Get(MessageFieldName), int.Parse(doc.Get(SourceIdFieldName)));
                result.Id = ulong.Parse(doc.Get(IdFieldName));
                return result;
            }
예제 #8
0
            public Document ToDocument(LogEntry entry)
            {
                machineField.SetValue(entry.MachineName ?? string.Empty);
                sourceField.SetValue(entry.ObjectName ?? string.Empty);
                idField.SetLongValue((long)entry.Id);
                typeField.SetValue(entry.Type.ToString());
                messageField.SetValue(entry.Message);
                timeField.SetLongValue(entry.Time.ToBinary());
                sourceIdField.SetIntValue(entry.SourceId);

                return document;
            }
예제 #9
0
 private static bool TryDeserializeEntry(PrimitiveReader reader, out LogEntry entry)
 {
     var localEntry = (LogEntry)FormatterServices.GetUninitializedObject(typeof(LogEntry));
     try 
     {
         localEntry.Load(reader);
         entry = localEntry;
         return true;
     } 
     catch (EndOfStreamException)
     {
         // intentionally left blank
     }
     entry = null;
     return false;
 }
예제 #10
0
 public void Add(LogEntry entry)
 {
     var copyOfWriter = currentWriter;
     Interlocked.Increment(ref copyOfWriter.ReferenceCounter);
     entry.Save(copyOfWriter.Writer);
     Interlocked.Decrement(ref copyOfWriter.ReferenceCounter);
 }
예제 #11
0
파일: ListViewLog.cs 프로젝트: rte-se/emul8
        public int InsertItem(LogEntry entry, bool scrollOnRefresh, int? limit = null)
        {
            var rowId = listStore.InsertRowBefore(0);

            listStore.SetValues(rowId, 
                imgField,       LogLevelToIcon(entry.Type),
                typeField,      entry.Type.ToString(),
                machineField,   entry.MachineName ?? string.Empty,
                objectField,    entry.ObjectName ?? string.Empty,
                textField,      entry.Message,
                timestampField, string.Format("{0:HH:mm:ss.ffff}", entry.Time),
                idField,        entry.Id);

            if(scrollOnRefresh || entry.Id == SelectedItemId)
            {
                SelectRow(rowId);
            }
            while (limit.HasValue && limit != 0 && listStore.RowCount > limit)
            {
                listStore.RemoveRow(listStore.RowCount - 1);
            }

            return rowId;
        }
예제 #12
0
파일: Logger.cs 프로젝트: rte-se/emul8
 private void WriteLogEntryToBackends(LogEntry entry)
 {
     var allBackends = Logger.backends.Items;
     for(var i = 0; i < allBackends.Length; i++)
     {
         allBackends[i].Log(entry);
     }
 }
예제 #13
0
파일: Logger.cs 프로젝트: rte-se/emul8
            public void ObjectInnerLog(object o, LogLevel type, string message, params object[] args)
            {
                int sourceId = (o == null) ? -1 : GetOrCreateSourceId(o);
                if(args.Length > 0)
                {
                    message = string.Format(message, args);
                }

                var entry = new LogEntry(CustomDateTime.Now, type, message, sourceId, Thread.CurrentThread.ManagedThreadId);

                if(useSynchronousLogging)
                {
                    lock(synchronousLoggingLock)
                    {
                        entry.Id = Logger.nextEntryId++;
                        WriteLogEntryToBackends(entry);
                    }
                }
                else
                {
                    entries.Add(entry);
                }
            }
예제 #14
0
            public void ObjectInnerLog(object o, LogLevel type, string message, params object[] args)
            {
                int sourceId = (o == null) ? -1 : GetOrCreateSourceId(o);
                if(args.Length > 0)
                {
                    message = string.Format(message, args);
                }

                var entry = new LogEntry(CustomDateTime.Now, type, message, sourceId, Thread.CurrentThread.ManagedThreadId);
                entries.Add(entry);
            }