//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldParseCheckPointEntry() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldParseCheckPointEntry() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final CheckPoint checkPoint = new CheckPoint(new org.neo4j.kernel.impl.transaction.log.LogPosition(43, 44)); CheckPoint checkPoint = new CheckPoint(new LogPosition(43, 44)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel channel = new org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel(); InMemoryClosableChannel channel = new InMemoryClosableChannel(); channel.PutLong(checkPoint.LogPosition.LogVersion); channel.PutLong(checkPoint.LogPosition.ByteOffset); channel.GetCurrentPosition(_marker); // when //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LogEntryParser parser = version.entryParser(LogEntryByteCodes.CHECK_POINT); LogEntryParser parser = _version.entryParser(LogEntryByteCodes.CheckPoint); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LogEntry logEntry = parser.parse(version, channel, marker, commandReader); LogEntry logEntry = parser.parse(_version, channel, _marker, _commandReader); // then assertEquals(checkPoint, logEntry); assertFalse(parser.skip()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldParserOnePhaseCommitEntry() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldParserOnePhaseCommitEntry() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LogEntryCommit commit = new LogEntryCommit(version, 42, 21); LogEntryCommit commit = new LogEntryCommit(_version, 42, 21); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel channel = new org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel(); InMemoryClosableChannel channel = new InMemoryClosableChannel(); channel.PutLong(commit.TxId); channel.PutLong(commit.TimeWritten); channel.GetCurrentPosition(_marker); // when //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LogEntryParser parser = version.entryParser(LogEntryByteCodes.TX_COMMIT); LogEntryParser parser = _version.entryParser(LogEntryByteCodes.TxCommit); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LogEntry logEntry = parser.parse(version, channel, marker, commandReader); LogEntry logEntry = parser.parse(_version, channel, _marker, _commandReader); // then assertEquals(commit, logEntry); assertFalse(parser.skip()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldParserStartEntry() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldParserStartEntry() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LogEntryStart start = new LogEntryStart(version, 1, 2, 3, 4, new byte[]{5}, position); LogEntryStart start = new LogEntryStart(_version, 1, 2, 3, 4, new sbyte[] { 5 }, _position); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel channel = new org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel(); InMemoryClosableChannel channel = new InMemoryClosableChannel(); channel.PutInt(start.MasterId); channel.PutInt(start.LocalId); channel.PutLong(start.TimeWritten); channel.PutLong(start.LastCommittedTxWhenTransactionStarted); channel.PutInt(start.AdditionalHeader.Length); channel.Put(start.AdditionalHeader, start.AdditionalHeader.Length); channel.GetCurrentPosition(_marker); // when //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LogEntryParser parser = version.entryParser(LogEntryByteCodes.TX_START); LogEntryParser parser = _version.entryParser(LogEntryByteCodes.TxStart); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LogEntry logEntry = parser.parse(version, channel, marker, commandReader); LogEntry logEntry = parser.parse(_version, channel, _marker, _commandReader); // then assertEquals(start, logEntry); assertFalse(parser.skip()); }
public void Parse_with_text_element() { var line = @"<log4j:event logger=""installrelease"" timestamp=""1388750967872"" level=""ERROR"" thread=""""><log4j:NDC></log4j:NDC><log4j:message>Caught Errno::EACCES: Permission denied - filesomething C:/Ruby193/lib/ruby/gems/1.9.1/gems/someliblib/lib/libloblob/libloblob.rb:42:in `block in download' C:/Ruby193/lib/ruby/gems/1.9.1/gems/someliblib/lib/libloblob/libloblob.rb:41:in `each' C:/Ruby193/lib/ruby/gems/1.9.1/gems/someliblib/lib/libloblob/libloblob.rb:41:in `download' install_release.rb:92:in `block in get_latest!'</log4j:message><log4j:throwable>Caught Errno::EACCES: Permission denied - file C:/Ruby193/lib/ruby/gems/1.9.1/gems/someliblib/lib/libloblob/libloblob.rb:42:in `block in download' C:/Ruby193/lib/ruby/gems/1.9.1/gems/someliblib/lib/libloblob/libloblob.rb:41:in `each' C:/Ruby193/lib/ruby/gems/1.9.1/gems/someliblib/lib/libloblob/libloblob.rb:41:in `download' install_release.rb:92:in `block in get_latest!'</log4j:throwable><log4j:locationInfo class="""" method="""" file="""" line=""""/><log4j:properties></log4j:properties></log4j:event>"; using (var s = new MemoryStream()) using (var w = new StreamWriter(s)) { w.Write(line); w.Flush(); s.Position = 0; var entry = new LogEntryParser().Parse(s).Single(); Assert.Equal("ERROR", entry.Data.Level.Name); Assert.True(entry.Data.Message.Contains(@"Caught Errno::EACCES: Permission denied - filesomething")); Assert.True(entry.Data.Message.Contains(@"install_release.rb:92:in `block in get_latest!'")); } }
public void Parse_with_empty_ndc_should_not_crash_parser() { //<log4j:NDC></log4j:NDC> using (var s = new MemoryStream()) using (var w = new StreamWriter(s)) { var line = @"<log4j:event logger=""IntegrationTests.LogTests"" timestamp=""1300909721869"" level=""ERROR"" thread=""7""> <log4j:NDC></log4j:NDC> <log4j:message>msg</log4j:message> <log4j:properties> <log4j:data name=""log4net:UserName"" value=""AWESOMEMACHINE\Administrator"" /> <log4j:data name=""log4jmachinename"" value=""AWESOMEMACHINE"" /> <log4j:data name=""log4japp"" value=""IsolatedAppDomainHost: IntegrationTests"" /> <log4j:data name=""log4net:HostName"" value=""AWESOMEMACHINE"" /> </log4j:properties> <log4j:throwable>System.Exception: test</log4j:throwable> <log4j:locationInfo class=""IntegrationTests.LogTests"" method=""TestLog"" file=""C:\projects\LogViewer\IntegrationTests\LogTests.cs"" line=""27"" /></log4j:event>" ; w.Write(line); w.Flush(); s.Position = 0; var entry = new LogEntryParser().Parse(s).Single(); Assert.Equal("ERROR", entry.Data.Level.Name); } }
public void Parse() { using (var s = new MemoryStream()) using (var w = new StreamWriter(s)) { var lines = @"<log4j:event logger=""HomeController"" timestamp=""1361528145331"" level=""ERROR"" thread=""91""> <log4j:message>error</log4j:message> <log4j:properties> <log4j:data name=""log4net:UserName"" value=""SOMEDOMAIN\someuser"" /> <log4j:data name=""log4net:Identity"" value=""44045"" /> <log4j:data name=""log4jmachinename"" value=""somemachine"" /> <log4j:data name=""log4japp"" value=""/LM/W3SVC/1"" /> <log4j:data name=""log4net:HostName"" value=""SOMEHOST"" /> </log4j:properties> <log4j:locationInfo class=""MyController"" method=""Log"" file=""C:\project\MyController.cs"" line=""99"" /> </log4j:event> "; w.Write(lines); w.Flush(); s.Position = 0; var entry = new LogEntryParser().Parse(s).Single(); Assert.Equal("44045", entry.Identity); } }
public void Object_payload_should_be_directly_assigned() { var le = new LogEntry(); var dto = LogEntryParser.ParseLogEntry(le, "app", "test"); dto.Payload.Should().BeSameAs(le.Payload); }
private LogEntryDto CreateDto(bool alternativeStackTrace = false, string message = errorMessage) { var le = new LogEntry { Exception = CreateException(alternativeStackTrace, message) }; return(LogEntryParser.ParseLogEntry(le, "app", "test")); }
public void ParseFaulty() { using (var s = FileUtil.OpenReadOnly("test.xml")) { var entry = new LogEntryParser().Parse(s).Single(); Assert.True(entry.Data.Message.Contains("Translation for 'Detta ska jag g"), "translation"); Assert.True(entry.Data.Message.Contains("ra...' in module Todo for culture sv-SE does not exist."), "in module"); } }
public void Simple_string_should_be_assigned_to_Message() { var le = new LogEntry { Payload = "hello world" }; var dto = LogEntryParser.ParseLogEntry(le, "app", "test"); dto.Payload.Should().BeNull(); dto.Message.Should().Be("hello world"); }
public IEnumerable <LogEntry> Read() { using (var stream = OpenLogSource()) { using (var reader = new StreamReader(stream)) { string line; while ((line = reader.ReadLine()) != null) { yield return(LogEntryParser.Parse(line)); } } } }
private static void TailFiles(int lines, List <string> files, Action <LogEntry> showentry) { foreach (var fileName in files) { using (var file = FileUtil.OpenReadOnly(fileName)) { var items = new LogEntryParser().Parse(file) .ToArray(); foreach (var logEntry in items.Skip(items.Count() - lines)) { showentry(logEntry); } } } }
public void Simple_string_should_be_wrapped_in_anonymous_type_if_message_is_in_use() { var le = new LogEntry { Payload = "hello world", Message = "foobar" }; var dto = LogEntryParser.ParseLogEntry(le, "app", "test"); dto.Message.Should().Be("foobar"); dto.Payload.Should().NotBeOfType <string>(); dynamic data = dto.Payload; string message = data.Message; message.Should().Be("hello world"); }
public void ParseStream() { using (var s = new MemoryStream()) using (var w = new StreamWriter(s)) { w.Write(_buffer); w.Flush(); s.Position = 0; var entry = new LogEntryParser().Parse(s).Single(); Assert.Equal("ERROR", entry.Data.Level.Name); Assert.Equal(@"AWESOMEMACHINE", entry.HostName); Assert.Equal(@"IsolatedAppDomainHost: IntegrationTests", entry.Data.Domain); Assert.Equal("msg", entry.Data.Message); Assert.Equal("IntegrationTests.LogTests", entry.Class()); Assert.Equal("TestLog", entry.Method()); Assert.Equal("19", entry.Line()); Assert.Equal(@"C:\projects\LogViewer\IntegrationTests\LogTests.cs", entry.File()); } }
public void ParseWithThrowableAsLastChildElement() { using (var s = new MemoryStream()) using (var w = new StreamWriter(s)) { var lines = @"<log4j:event logger=""IntegrationTests.LogTests"" timestamp=""1300909721869"" level=""ERROR"" thread=""7""> <log4j:message>msg</log4j:message> <log4j:properties> <log4j:data name=""log4net:UserName"" value=""AWESOMEMACHINE\Administrator"" /> <log4j:data name=""log4jmachinename"" value=""AWESOMEMACHINE"" /> <log4j:data name=""log4japp"" value=""IsolatedAppDomainHost: IntegrationTests"" /> <log4j:data name=""log4net:HostName"" value=""AWESOMEMACHINE"" /> </log4j:properties> <log4j:locationInfo class=""IntegrationTests.LogTests"" method=""TestLog"" file=""C:\projects\LogViewer\IntegrationTests\LogTests.cs"" line=""27"" /> <log4j:throwable>System.Exception: test</log4j:throwable></log4j:event> <log4j:event logger=""HomeController"" timestamp=""1361528145331"" level=""ERROR"" thread=""91""> <log4j:message>error</log4j:message> <log4j:properties> <log4j:data name=""log4net:UserName"" value=""SOMEDOMAIN\someuser"" /> <log4j:data name=""log4net:Identity"" value=""44045"" /> <log4j:data name=""log4jmachinename"" value=""somemachine"" /> <log4j:data name=""log4japp"" value=""/LM/W3SVC/1"" /> <log4j:data name=""log4net:HostName"" value=""SOMEHOST"" /> </log4j:properties> <log4j:locationInfo class=""MyController"" method=""Log"" file=""C:\project\MyController.cs"" line=""99"" /> </log4j:event>"; w.Write(lines); w.Flush(); s.Position = 0; var entry = new LogEntryParser().Parse(s).ToList(); Assert.Equal(2, entry.Count); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldParserCommandsUsingAGivenFactory() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldParserCommandsUsingAGivenFactory() { // given // The record, it will be used as before and after NodeRecord theRecord = new NodeRecord(1); Command.NodeCommand nodeCommand = new Command.NodeCommand(theRecord, theRecord); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LogEntryCommand command = new LogEntryCommand(version, nodeCommand); LogEntryCommand command = new LogEntryCommand(_version, nodeCommand); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel channel = new org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel(); InMemoryClosableChannel channel = new InMemoryClosableChannel(); channel.Put(Org.Neo4j.Kernel.impl.transaction.command.NeoCommandType_Fields.NodeCommand); channel.PutLong(theRecord.Id); // record image before channel.Put(( sbyte )0); // not in use channel.PutInt(0); // number of dynamic records in use // record image after channel.Put(( sbyte )0); // not in use channel.PutInt(0); // number of dynamic records in use channel.GetCurrentPosition(_marker); // when //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LogEntryParser parser = version.entryParser(LogEntryByteCodes.COMMAND); LogEntryParser parser = _version.entryParser(LogEntryByteCodes.Command); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LogEntry logEntry = parser.parse(version, channel, marker, commandReader); LogEntry logEntry = parser.parse(_version, channel, _marker, _commandReader); // then assertEquals(command, logEntry); assertFalse(parser.skip()); }
public void ParseStreamAtPosition() { long p = 0; var path = Path.GetTempFileName(); using (var s = new FileStream(path, FileMode.Truncate, FileAccess.ReadWrite)) using (var w = new StreamWriter(s)) { w.Write(_buffer); w.Flush(); s.Position = 0; var entry = new LogEntryParser().Parse(s).Single();// read written entry p = s.Position; } using (var s = new FileStream(path, FileMode.Append, FileAccess.Write)) using (var w = new StreamWriter(s)) { w.Write(_buffer); w.Flush(); } using (var s = FileUtil.OpenReadOnly(path, position: p)) { var entry = new LogEntryParser().Parse(s).Single(); Assert.Equal("ERROR", entry.Data.Level.Name); Assert.Equal(@"AWESOMEMACHINE", entry.HostName); Assert.Equal(@"IsolatedAppDomainHost: IntegrationTests", entry.Data.Domain); Assert.Equal("msg", entry.Data.Message); Assert.Equal("IntegrationTests.LogTests", entry.Class()); Assert.Equal("TestLog", entry.Method()); Assert.Equal("19", entry.Line()); Assert.Equal(@"C:\projects\LogViewer\IntegrationTests\LogTests.cs", entry.File()); } }
public void ParseStreamAtPositionShouldThrowException() { long p = 0; var path = Path.GetTempFileName(); using (var s = new FileStream(path, FileMode.Truncate, FileAccess.ReadWrite)) using (var w = new StreamWriter(s)) { w.Write(_buffer); w.Flush(); s.Position = 0; var entry = new LogEntryParser().Parse(s).Single();// read written entry p = s.Position; } Assert.Throws <OutOfBoundsException>(() => { using (var s = FileUtil.OpenReadOnly(path, position: p * 10)) { new LogEntryParser().Parse(s); } }); }
public Poller(IFileWithPosition file, long duration, LogEntryParser parser = null, IInvoker invoker = null) : base(file, parser, invoker) { this.duration = duration; }
static void Main(string[] args) { var files = new List <string>(); int monitor = 0; int? lines = null; var watch = false; LayoutSkeleton layout = null; var help = false; var p = new OptionSet() { { "i|file=", v => { files.Add(v); } }, { "m|monitor=", v => { monitor = ParseInterval(v); } }, { "w|watch", v => { watch = true; } }, { "l|lines=", v => { lines = Int32.Parse(v); } }, { "h|?|help", v => { help = true; } }, { "y|layout=", v => { layout = new PatternLayout(v); } }, { "f|format=", v => { layout = GetFormatLayout(v); } } }; var detectedFiles = args .Where(a => !(a.StartsWith("-") || a.StartsWith("/"))) .Where(a => File.Exists(a)); files.AddRange(detectedFiles); p.Parse(args); if (layout == null) { layout = new SimpleLayout(); } Action <TextWriter, LogEntry> showentry = (writer, l) => layout.Format(writer, new LoggingEvent(l.Data)); if (help) { Console.WriteLine(@"Usage: -i|file={a filename} The (input) file to watch, monitor or -l|lines={tail x lines} Display the last x lines. Defaults to 10 lines. -y|layout={pattern layout syntax as defined in log4net.Layout.PatternLayout} -f|format={a named layout format} The available formats are: -f=minusminus Information delimited by newline and ---------------------- -h|?|help Display help -w|watch Use file system watcher to watch file -m|monitor=seconds Use polling to check for changes of the file. For instance to : LogTail.exe -f=logfile.xml LogTail.exe -file=logfile.xml If you are in powershell (or cygwin) you can do the following: cat yourlogfile.xml | LogTail.exe "); return; } if (watch) { var w = new Watcher <LogEntry>(new FileWithPosition(files.Single()), new LogEntryParser()); w.LogEntry += (entry) => showentry(Console.Out, entry); Do(w); return; } if (monitor > 0) { var w = new Poller <LogEntry>(new FileWithPosition(files.Single()), monitor, new LogEntryParser()); w.LogEntry += (entry) => showentry(Console.Out, entry); Do(w); return; } if (files.Any()) { TailFiles(lines ?? 10, files, (entry) => showentry(Console.Out, entry)); return; } else { Console.WriteLine("No files, listening to standard input."); using (Stream stdin = Console.OpenStandardInput()) using (Stream stdout = Console.OpenStandardOutput()) using (StreamWriter writer = new StreamWriter(stdout)) { var items = new LogEntryParser().Parse(stdin).ToArray(); foreach (var logEntry in items.Skip(items.Count() - (lines ?? 10))) { showentry(writer, logEntry); } } return; } }
private ILogFileWatcher<LogEntry> CreateLogFileWatcher(string value, LogEntryParser parser) { return new Watcher<LogEntry>(new FileWithPosition(value), parser, wrappedDispatcher); }
public LogImporter(string logFile) { // Создаем нужный парсер в зависимости от имени файла _parser = LogEntryParser.Create(logFile); }
public LogFileWatcherBase(IFileWithPosition file, LogEntryParser parser = null, IInvoker invoker = null) { this.File = file; this.parser = parser ?? new LogEntryParser(); this.invoker = invoker ?? new DirectInvoker(); }
public Watcher(IFileWithPosition file, LogEntryParser parser = null, IInvoker invoker = null) : base(file, parser, invoker) { }
private ILogFileWatcher <LogEntry> CreateLogFileWatcher(string value, LogEntryParser parser) { return(new Watcher <LogEntry>(new FileWithPosition(value), parser, wrappedDispatcher)); }