ILogger.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Ryujinx.HLE.Logging;
  2. using Ryujinx.HLE.OsHle.Ipc;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Text;
  6. namespace Ryujinx.HLE.OsHle.Services.Lm
  7. {
  8. class ILogger : IpcService
  9. {
  10. private Dictionary<int, ServiceProcessRequest> m_Commands;
  11. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  12. public ILogger()
  13. {
  14. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  15. {
  16. { 0, Log }
  17. };
  18. }
  19. public long Log(ServiceCtx Context)
  20. {
  21. byte[] LogBuffer = Context.Memory.ReadBytes(
  22. Context.Request.PtrBuff[0].Position,
  23. Context.Request.PtrBuff[0].Size);
  24. using (MemoryStream MS = new MemoryStream(LogBuffer))
  25. {
  26. BinaryReader Reader = new BinaryReader(MS);
  27. long Pid = Reader.ReadInt64();
  28. long ThreadContext = Reader.ReadInt64();
  29. short Flags = Reader.ReadInt16();
  30. byte Level = Reader.ReadByte();
  31. byte Verbosity = Reader.ReadByte();
  32. int PayloadLength = Reader.ReadInt32();
  33. StringBuilder SB = new StringBuilder();
  34. SB.AppendLine("Guest log:");
  35. while (MS.Position < MS.Length)
  36. {
  37. byte Type = Reader.ReadByte();
  38. byte Size = Reader.ReadByte();
  39. LmLogField Field = (LmLogField)Type;
  40. string FieldStr = string.Empty;
  41. if (Field == LmLogField.Skip)
  42. {
  43. Reader.ReadByte();
  44. continue;
  45. }
  46. else if (Field == LmLogField.Line)
  47. {
  48. FieldStr = Field + ": " + Reader.ReadInt32();
  49. }
  50. else
  51. {
  52. FieldStr = Field + ": \"" + Encoding.UTF8.GetString(Reader.ReadBytes(Size)) + "\"";
  53. }
  54. SB.AppendLine(" " + FieldStr);
  55. }
  56. string Text = SB.ToString();
  57. switch((LmLogLevel)Level)
  58. {
  59. case LmLogLevel.Trace: Context.Ns.Log.PrintDebug (LogClass.ServiceLm, Text); break;
  60. case LmLogLevel.Info: Context.Ns.Log.PrintInfo (LogClass.ServiceLm, Text); break;
  61. case LmLogLevel.Warning: Context.Ns.Log.PrintWarning(LogClass.ServiceLm, Text); break;
  62. case LmLogLevel.Error: Context.Ns.Log.PrintError (LogClass.ServiceLm, Text); break;
  63. case LmLogLevel.Critical: Context.Ns.Log.PrintError (LogClass.ServiceLm, Text); break;
  64. }
  65. }
  66. return 0;
  67. }
  68. }
  69. }