Coder Social home page Coder Social logo

ravenunity's Introduction

RavenUnity

Butchered version of https://github.com/kimsama/Unity3D-Raven for use with Unity 5.x

Note: This could be optimized quite a bit, especially with respect to garbage generation. However, every time Unity fires an Exception it already creates so much garbage that a little bit extra doesn't matter.

Example usage:

using System;
using UnityEngine;
using System.Collections.Generic;
using RamjetAnvil.Volo;
using SharpRaven;

public class ErrorReporter : MonoBehaviour {
    [SerializeField] private string _dsnUrl = "http://pub:[email protected]/12345";

    private RavenClient _ravenClient;
    private Queue<UnityLogEvent> _messageQueue;
    private Dictionary<string, string> _clientInfoTags;

    private void Awake()
    {
	    DontDestroyOnLoad(gameObject);
        _messageQueue = new Queue<UnityLogEvent>();
        CreateRavenClient();
    }

    private void OnEnable() {
        Application.logMessageReceived += HandleLog;
    }

    private void OnDisable() {
        Application.logMessageReceived -= HandleLog;
    }

    private void CreateRavenClient() {
        _ravenClient = new RavenClient(_dsnUrl, this);
        _ravenClient.Logger = "Unity";
        _ravenClient.LogScrubber = new SharpRaven.Logging.LogScrubber();

        _clientInfoTags = new Dictionary<string, string>();

        _clientInfoTags.Add("Version", "-1");
        _clientInfoTags.Add("UnityVersion", Application.unityVersion);

        _clientInfoTags.Add("OS", SystemInfo.operatingSystem);

        _clientInfoTags.Add("ProcessorType", SystemInfo.processorType);
        _clientInfoTags.Add("ProcessorCount", SystemInfo.processorCount.ToString());
    
        _clientInfoTags.Add("MemorySize", SystemInfo.systemMemorySize.ToString());
        _clientInfoTags.Add("Screen-Resolution", Screen.currentResolution.ToString()); // Note: can change at runtime

        _clientInfoTags.Add("GPU-Memory", SystemInfo.graphicsMemorySize.ToString());
        _clientInfoTags.Add("GPU-Name", SystemInfo.graphicsDeviceName);
        _clientInfoTags.Add("GPU-Vendor", SystemInfo.graphicsDeviceVendor);
        _clientInfoTags.Add("GPU-VendorID", SystemInfo.graphicsDeviceVendorID.ToString());
        _clientInfoTags.Add("GPU-id", SystemInfo.graphicsDeviceID.ToString());
        _clientInfoTags.Add("GPU-Version", SystemInfo.graphicsDeviceVersion);
        _clientInfoTags.Add("GPU-ShaderLevel", SystemInfo.graphicsShaderLevel.ToString());

        // Todo: vr info
    }

    public void SetVersionInfo(VersionInfo version) {
        _clientInfoTags["Version"] = version.VersionNumber;
    }

    private void Update() {
        while (_messageQueue.Count > 0) {
            var message = _messageQueue.Dequeue();
            var packet = _ravenClient.CreatePacket(message);
            packet.Tags = _clientInfoTags;
            _ravenClient.Send(packet);
        }
    }

    private void HandleLog(string log, string stack, LogType type) {
        switch (type) {
            case LogType.Error:
                CaptureUnityLog(log, stack, type);
                break;
            case LogType.Assert:
                break;
            case LogType.Warning:
                break;
            case LogType.Log:
                break;
            case LogType.Exception:
                CaptureUnityLog(log, stack, type);
                break;
            default:
                throw new ArgumentOutOfRangeException("type", type, null);
        }
    }

    private void CaptureUnityLog(string message, string stack, LogType logType) {
        _messageQueue.Enqueue(new UnityLogEvent() {
            LogType = logType,
            Message = message,
            StackTrace = stack
        });
    }
}

ravenunity's People

Contributors

mzandvliet avatar

Stargazers

Frank Versnel avatar

Watchers

Frank Versnel avatar  avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.