﻿using UnityEngine;
using System.Collections;
using System;

public class LoggingExample : MonoBehaviour {

    public GameObject target;
    public int iterations = 1000;
    private int start;
	// Use this for initialization
	void Start () {
        Debug.Log("Start");

        if (target == null)
        {
            Debug.LogWarning("target object not set");
        }

        if (iterations < 1)
        {
            Debug.LogWarningFormat("interations: {0} < 1", iterations);
        }

        Debug.LogFormat("{0} iterations set", iterations);
        start = iterations;
	}
	
	// Update is called once per frame
	void Update () {
        //try/catch used for demo
        //never use in an update method
        try
        {
            iterations--;
            Debug.LogFormat("Progress {0}%", (100 - iterations / start * 100));
        }
        catch (Exception ex)
        {
            Debug.LogError("Error encountered " + ex.Message);
            Debug.LogErrorFormat("Error at {0} iterations, msg = {1}", iterations, ex.Message);
            Debug.LogException(ex);
        }
	}
}
