BuglyInit.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // ----------------------------------------
  2. //
  3. // BuglyInit.cs
  4. //
  5. // Author:
  6. // Yeelik, <bugly@tencent.com>
  7. //
  8. // Copyright (c) 2015 Bugly, Tencent. All rights reserved.
  9. //
  10. // ----------------------------------------
  11. //
  12. using UnityEngine;
  13. using System.Collections;
  14. using System.Collections.Generic;
  15. public class BuglyInit : MonoBehaviour
  16. {
  17. /// <summary>
  18. /// Your Bugly App ID. Every app has a special identifier that allows Bugly to associate error monitoring data with your app.
  19. /// Your App ID can be found on the "Setting" page of the app you are trying to monitor.
  20. /// </summary>
  21. /// <example>A real App ID looks like this: 90000xxxx</example>
  22. private const string BuglyAppID = "YOUR APP ID GOES HERE";
  23. void Awake ()
  24. {
  25. // Enable the debug log print
  26. BuglyAgent.ConfigDebugMode (false);
  27. // Config default channel, version, user
  28. BuglyAgent.ConfigDefault (null, null, null, 0);
  29. // Config auto report log level, default is LogSeverity.LogError, so the LogError, LogException log will auto report
  30. BuglyAgent.ConfigAutoReportLogLevel (LogSeverity.LogError);
  31. // Config auto quit the application make sure only the first one c# exception log will be report, please don't set TRUE if you do not known what are you doing.
  32. BuglyAgent.ConfigAutoQuitApplication (false);
  33. // If you need register Application.RegisterLogCallback(LogCallback), you can replace it with this method to make sure your function is ok.
  34. BuglyAgent.RegisterLogCallback (null);
  35. // Init the bugly sdk and enable the c# exception handler.
  36. BuglyAgent.InitWithAppId (BuglyAppID);
  37. // TODO Required. If you do not need call 'InitWithAppId(string)' to initialize the sdk(may be you has initialized the sdk it associated Android or iOS project),
  38. // please call this method to enable c# exception handler only.
  39. BuglyAgent.EnableExceptionHandler ();
  40. // TODO NOT Required. If you need to report extra data with exception, you can set the extra handler
  41. BuglyAgent.SetLogCallbackExtrasHandler (MyLogCallbackExtrasHandler);
  42. Destroy (this);
  43. }
  44. // Extra data handler to packet data and report them with exception.
  45. // Please do not do hard work in this handler
  46. static Dictionary<string, string> MyLogCallbackExtrasHandler ()
  47. {
  48. // TODO Test log, please do not copy it
  49. BuglyAgent.PrintLog (LogSeverity.Log, "extra handler");
  50. // TODO Sample code, please do not copy it
  51. Dictionary<string, string> extras = new Dictionary<string, string> ();
  52. extras.Add ("ScreenSolution", string.Format ("{0}x{1}", Screen.width, Screen.height));
  53. extras.Add ("deviceModel", SystemInfo.deviceModel);
  54. extras.Add ("deviceName", SystemInfo.deviceName);
  55. extras.Add ("deviceType", SystemInfo.deviceType.ToString ());
  56. extras.Add ("deviceUId", SystemInfo.deviceUniqueIdentifier);
  57. extras.Add ("gDId", string.Format ("{0}", SystemInfo.graphicsDeviceID));
  58. extras.Add ("gDName", SystemInfo.graphicsDeviceName);
  59. extras.Add ("gDVdr", SystemInfo.graphicsDeviceVendor);
  60. extras.Add ("gDVer", SystemInfo.graphicsDeviceVersion);
  61. extras.Add ("gDVdrID", string.Format ("{0}", SystemInfo.graphicsDeviceVendorID));
  62. extras.Add ("graphicsMemorySize", string.Format ("{0}", SystemInfo.graphicsMemorySize));
  63. extras.Add ("systemMemorySize", string.Format ("{0}", SystemInfo.systemMemorySize));
  64. extras.Add ("UnityVersion", Application.unityVersion);
  65. BuglyAgent.PrintLog (LogSeverity.LogInfo, "Package extra data");
  66. return extras;
  67. }
  68. }