aboutsummaryrefslogtreecommitdiffstats
path: root/reference/csharp/eina/src/eina_log.cs
blob: ca8cce88b289e7d55f1a49d23d974284a2447b2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

/*
 * Efl Core Log examples.
 *
 * This demo shows how to log at various levels and to change what log is shown.
 * You can also use a custom log printer in your app as shown in _log_custom.
 */

using System;

public class Example
{
    static double Divide(int num, int denom)
    {
        if (denom == 0)
            eina.Log.Critical("Attempt to divide by 0\n");
        else
        {
            if (denom < 0)
                eina.Log.Warning("Possible undesirable effect, divide by negative number");

            double ret = ((double) num / denom);
            eina.Log.Info($"{num} / {denom} = {ret}\n");
            return ret;
        }

        return -1;
    }

    static void Divides()
    {
        Divide(5, 1);
        Divide(5, -1);
        Divide(5, 0);
    }

    static void LogLevels()
    {
        Console.WriteLine("Executing with default logging");
        Divides();

        eina.Log.GlobalLevelSet(eina.Log.Level.Warning);
        Console.WriteLine("Executing with Warning level"); // same as EINA_LOG_LEVEL = 2
        Divides();

        eina.Log.GlobalLevelSet(eina.Log.Level.Info);
        Console.WriteLine("Executing with Info on"); // same as EINA_LOG_LEVEL = 3
        Divides();
    }

    public static void Main()
    {
        efl.All.Init();

        LogLevels();

        // TODO: missing
        //LogCustom();

        efl.All.Shutdown();
    }
}