7ade430f1d0714e6042fa5eab6d65402551215fe
[platform/core/csapi/tizenfx.git] / src / Tizen / Tizen / Log.cs
1 // Copyright 2016 by Samsung Electronics, Inc.,
2 //
3 // This software is the confidential and proprietary information
4 // of Samsung Electronics, Inc. ("Confidential Information"). You
5 // shall not disclose such Confidential Information and shall use
6 // it only in accordance with the terms of the license agreement
7 // you entered into with Samsung.
8
9 using System;
10 using System.IO;
11 using System.Runtime.CompilerServices;
12
13 namespace Tizen
14 {
15     /// <summary>
16     /// Provides methods to print log messages to Tizen logging system.
17     /// </summary>
18     public static class Log
19     {
20         /// <summary>
21         /// Prints a log message with the DEBUG priority.
22         /// </summary>
23         /// <param name="tag">The tag name of the log message.</param>
24         /// <param name="message">The log message to print.</param>
25         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
26         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
27         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
28         public static void Debug(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
29         {
30             if (String.IsNullOrEmpty(file))
31             {
32                 Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_DEBUG, tag, "%s", message);
33             }
34             else
35             {
36                 Uri f = new Uri(file);
37                 Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_DEBUG, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, message);
38             }
39         }
40
41         /// <summary>
42         /// Prints a log message with the VERBOSE priority.
43         /// </summary>
44         /// <param name="tag">The tag name of the log message.</param>
45         /// <param name="message">The log message to print.</param>
46         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
47         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
48         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
49         public static void Verbose(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
50         {
51             if (String.IsNullOrEmpty(file))
52             {
53                 Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_VERBOSE, tag, "%s", message);
54             }
55             else
56             {
57                 Uri f = new Uri(file);
58                 Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_VERBOSE, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, message);
59             }
60         }
61
62         /// <summary>
63         /// Prints a log message with the INFO priority.
64         /// </summary>
65         /// <param name="tag">The tag name of the log message.</param>
66         /// <param name="message">The log message to print.</param>
67         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
68         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
69         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
70         public static void Info(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
71         {
72             if (String.IsNullOrEmpty(file))
73             {
74                 Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_INFO, tag, "%s", message);
75             }
76             else
77             {
78                 Uri f = new Uri(file);
79                 Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_INFO, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, message);
80             }
81         }
82
83         /// <summary>
84         /// Prints a log message with the WARNING priority.
85         /// </summary>
86         /// <param name="tag">The tag name of the log message.</param>
87         /// <param name="message">The log message to print.</param>
88         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
89         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
90         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
91         public static void Warn(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
92         {
93             if (String.IsNullOrEmpty(file))
94             {
95                 Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_WARN, tag, "%s", message);
96             }
97             else
98             {
99                 Uri f = new Uri(file);
100                 Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_WARN, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, message);
101             }
102         }
103
104         /// <summary>
105         /// Prints a log message with the ERROR priority.
106         /// </summary>
107         /// <param name="tag">The tag name of the log message.</param>
108         /// <param name="message">The log message to print.</param>
109         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
110         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
111         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
112         public static void Error(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
113         {
114             if (String.IsNullOrEmpty(file))
115             {
116                 Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_ERROR, tag, "%s", message);
117             }
118             else
119             {
120                 Uri f = new Uri(file);
121                 Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_ERROR, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, message);
122             }
123         }
124
125         /// <summary>
126         /// Prints a log message with the FATAL priority.
127         /// </summary>
128         /// <param name="tag">The tag name of the log message.</param>
129         /// <param name="message">The log message to print.</param>
130         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
131         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
132         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
133         public static void Fatal(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
134         {
135             if (String.IsNullOrEmpty(file))
136             {
137                 Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_FATAL, tag, "%s", message);
138             }
139             else
140             {
141                 Uri f = new Uri(file);
142                 Interop.Dlog.Print(Interop.Dlog.LogPriority.DLOG_FATAL, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, message);
143             }
144         }
145     }
146 }