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