[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / Tizen.Log / Tizen / Log.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.IO;
19 using System.Runtime.CompilerServices;
20 using System.ComponentModel;
21
22 namespace Tizen
23 {
24     /// <summary>
25     /// Provides methods to print log messages to the Tizen logging system.
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     public class Log
29     {
30         /// <summary>
31         /// Prints a log message with the VERBOSE priority.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         /// <param name="tag">The tag name of the log message.</param>
35         /// <param name="message">The log message to print.</param>
36         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
37         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
38         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
39         public static void Verbose(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
40         {
41             Print(Interop.Dlog.LogPriority.DLOG_VERBOSE, tag, message, file, func, line);
42         }
43
44         /// <summary>
45         /// Prints a log message with the DEBUG priority.
46         /// </summary>
47         /// <since_tizen> 3 </since_tizen>
48         /// <param name="tag">The tag name of the log message.</param>
49         /// <param name="message">The log message to print.</param>
50         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
51         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
52         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
53         public static void Debug(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
54         {
55             Print(Interop.Dlog.LogPriority.DLOG_DEBUG, tag, message, file, func, line);
56         }
57
58         /// <summary>
59         /// Prints a log message with the INFO priority.
60         /// </summary>
61         /// <since_tizen> 3 </since_tizen>
62         /// <param name="tag">The tag name of the log message.</param>
63         /// <param name="message">The log message to print.</param>
64         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
65         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
66         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
67         public static void Info(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
68         {
69             Print(Interop.Dlog.LogPriority.DLOG_INFO, tag, message, file, func, line);
70         }
71
72         /// <summary>
73         /// Prints a log message with the WARNING priority.
74         /// </summary>
75         /// <since_tizen> 3 </since_tizen>
76         /// <param name="tag">The tag name of the log message.</param>
77         /// <param name="message">The log message to print.</param>
78         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
79         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
80         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
81         public static void Warn(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
82         {
83             Print(Interop.Dlog.LogPriority.DLOG_WARN, tag, message, file, func, line);
84         }
85
86         /// <summary>
87         /// Prints a log message with the ERROR priority.
88         /// </summary>
89         /// <since_tizen> 3 </since_tizen>
90         /// <param name="tag">The tag name of the log message.</param>
91         /// <param name="message">The log message to print.</param>
92         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
93         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
94         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
95         public static void Error(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
96         {
97             Print(Interop.Dlog.LogPriority.DLOG_ERROR, tag, message, file, func, line);
98         }
99
100         /// <summary>
101         /// Prints a log message with the FATAL priority.
102         /// </summary>
103         /// <since_tizen> 3 </since_tizen>
104         /// <param name="tag">The tag name of the log message.</param>
105         /// <param name="message">The log message to print.</param>
106         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
107         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
108         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
109         public static void Fatal(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
110         {
111             Print(Interop.Dlog.LogPriority.DLOG_FATAL, tag, message, file, func, line);
112         }
113
114         static void Print(Interop.Dlog.LogPriority priority, string tag, string message, string file, string func, int line)
115         {
116             if (String.IsNullOrEmpty(file))
117             {
118                 Interop.Dlog.Print(priority, tag, "%s", message);
119             }
120             else
121             {
122                 Uri f = new Uri("file://" + file);
123                 Interop.Dlog.Print(priority, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, message);
124             }
125         }
126     }
127
128     /// <summary>
129     /// Provides methods to print log messages to the Tizen logging system.
130     /// </summary>
131     /// <since_tizen> 3 </since_tizen>
132     [EditorBrowsable(EditorBrowsableState.Never)]
133     public class InternalLog
134     {
135         /// <summary>
136         /// Prints a log message with the VERBOSE priority.
137         /// </summary>
138         /// <since_tizen> 3 </since_tizen>
139         /// <param name="tag">The tag name of the log message.</param>
140         /// <param name="message">The log message to print.</param>
141         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
142         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
143         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
144         public static void Verbose(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
145         {
146             // For internal dlog APIs, Verbose level log is disabled
147             // Print(Interop.Dlog.LogID.LOG_ID_MAIN, Interop.Dlog.LogPriority.DLOG_VERBOSE, tag, message, file, func, line);
148         }
149
150         /// <summary>
151         /// Prints a log message with the DEBUG priority.
152         /// </summary>
153         /// <since_tizen> 3 </since_tizen>
154         /// <param name="tag">The tag name of the log message.</param>
155         /// <param name="message">The log message to print.</param>
156         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
157         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
158         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
159         public static void Debug(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
160         {
161             Print(Interop.Dlog.LogID.LOG_ID_MAIN, Interop.Dlog.LogPriority.DLOG_DEBUG, tag, message, file, func, line);
162         }
163
164         /// <summary>
165         /// Prints a log message with the INFO priority.
166         /// </summary>
167         /// <since_tizen> 3 </since_tizen>
168         /// <param name="tag">The tag name of the log message.</param>
169         /// <param name="message">The log message to print.</param>
170         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
171         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
172         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
173         public static void Info(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
174         {
175             Print(Interop.Dlog.LogID.LOG_ID_MAIN, Interop.Dlog.LogPriority.DLOG_INFO, tag, message, file, func, line);
176         }
177
178         /// <summary>
179         /// Prints a log message with the WARNING priority.
180         /// </summary>
181         /// <since_tizen> 3 </since_tizen>
182         /// <param name="tag">The tag name of the log message.</param>
183         /// <param name="message">The log message to print.</param>
184         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
185         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
186         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
187         public static void Warn(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
188         {
189             Print(Interop.Dlog.LogID.LOG_ID_MAIN, Interop.Dlog.LogPriority.DLOG_WARN, tag, message, file, func, line);
190         }
191
192         /// <summary>
193         /// Prints a log message with the ERROR priority.
194         /// </summary>
195         /// <since_tizen> 3 </since_tizen>
196         /// <param name="tag">The tag name of the log message.</param>
197         /// <param name="message">The log message to print.</param>
198         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
199         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
200         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
201         public static void Error(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
202         {
203             Print(Interop.Dlog.LogID.LOG_ID_MAIN, Interop.Dlog.LogPriority.DLOG_ERROR, tag, message, file, func, line);
204         }
205
206         /// <summary>
207         /// Prints a log message with the FATAL priority.
208         /// </summary>
209         /// <since_tizen> 3 </since_tizen>
210         /// <param name="tag">The tag name of the log message.</param>
211         /// <param name="message">The log message to print.</param>
212         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
213         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
214         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
215         public static void Fatal(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
216         {
217             Print(Interop.Dlog.LogID.LOG_ID_MAIN, Interop.Dlog.LogPriority.DLOG_FATAL, tag, message, file, func, line);
218         }
219
220         static void Print(Interop.Dlog.LogID log_id, Interop.Dlog.LogPriority priority, string tag, string message, string file, string func, int line)
221         {
222             if (String.IsNullOrEmpty(file))
223             {
224                 Interop.Dlog.InternalPrint(log_id, priority, tag, "%s", message);
225             }
226             else
227             {
228                 Uri f = new Uri("file://" + file);
229                 Interop.Dlog.InternalPrint(log_id, priority, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, message);
230             }
231         }
232     }
233
234     /// <summary>
235     /// Provides methods to print log messages to the Tizen logging system.
236     /// </summary>
237     /// <since_tizen> 3 </since_tizen>
238     [EditorBrowsable(EditorBrowsableState.Never)]
239     public class SecureLog
240     {
241         /// <summary>
242         /// Prints a log message with the VERBOSE priority.
243         /// </summary>
244         /// <since_tizen> 3 </since_tizen>
245         /// <param name="tag">The tag name of the log message.</param>
246         /// <param name="message">The log message to print.</param>
247         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
248         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
249         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
250         public static void Verbose(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
251         {
252             // For internal dlog APIs, Verbose level log is disabled
253             // Print(Interop.Dlog.LogID.LOG_ID_MAIN, Interop.Dlog.LogPriority.DLOG_VERBOSE, tag, message, file, func, line);
254         }
255
256         /// <summary>
257         /// Prints a log message with the DEBUG priority.
258         /// </summary>
259         /// <since_tizen> 3 </since_tizen>
260         /// <param name="tag">The tag name of the log message.</param>
261         /// <param name="message">The log message to print.</param>
262         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
263         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
264         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
265         public static void Debug(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
266         {
267             Print(Interop.Dlog.LogID.LOG_ID_MAIN, Interop.Dlog.LogPriority.DLOG_DEBUG, tag, message, file, func, line);
268         }
269
270         /// <summary>
271         /// Prints a log message with the INFO priority.
272         /// </summary>
273         /// <since_tizen> 3 </since_tizen>
274         /// <param name="tag">The tag name of the log message.</param>
275         /// <param name="message">The log message to print.</param>
276         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
277         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
278         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
279         public static void Info(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
280         {
281             Print(Interop.Dlog.LogID.LOG_ID_MAIN, Interop.Dlog.LogPriority.DLOG_INFO, tag, message, file, func, line);
282         }
283
284         /// <summary>
285         /// Prints a log message with the WARNING priority.
286         /// </summary>
287         /// <since_tizen> 3 </since_tizen>
288         /// <param name="tag">The tag name of the log message.</param>
289         /// <param name="message">The log message to print.</param>
290         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
291         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
292         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
293         public static void Warn(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
294         {
295             Print(Interop.Dlog.LogID.LOG_ID_MAIN, Interop.Dlog.LogPriority.DLOG_WARN, tag, message, file, func, line);
296         }
297
298         /// <summary>
299         /// Prints a log message with the ERROR priority.
300         /// </summary>
301         /// <since_tizen> 3 </since_tizen>
302         /// <param name="tag">The tag name of the log message.</param>
303         /// <param name="message">The log message to print.</param>
304         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
305         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
306         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
307         public static void Error(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
308         {
309             Print(Interop.Dlog.LogID.LOG_ID_MAIN, Interop.Dlog.LogPriority.DLOG_ERROR, tag, message, file, func, line);
310         }
311
312         /// <summary>
313         /// Prints a log message with the FATAL priority.
314         /// </summary>
315         /// <since_tizen> 3 </since_tizen>
316         /// <param name="tag">The tag name of the log message.</param>
317         /// <param name="message">The log message to print.</param>
318         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
319         /// <param name="func">The function name of the caller function. This argument will be set automatically by the compiler.</param>
320         /// <param name="line">The line number of the calling position. This argument will be set automatically by the compiler.</param>
321         public static void Fatal(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
322         {
323             Print(Interop.Dlog.LogID.LOG_ID_MAIN, Interop.Dlog.LogPriority.DLOG_FATAL, tag, message, file, func, line);
324         }
325
326         static void Print(Interop.Dlog.LogID log_id, Interop.Dlog.LogPriority priority, string tag, string message, string file, string func, int line)
327         {
328 #if !DISABLE_SECURELOG
329             if (String.IsNullOrEmpty(file))
330             {
331                 Interop.Dlog.InternalPrint(log_id, priority, tag, "[SECURE_LOG] %s", message);
332             }
333             else
334             {
335                 Uri f = new Uri("file://" + file);
336                 Interop.Dlog.InternalPrint(log_id, priority, tag, "%s: %s(%d) > [SECURE_LOG] %s", Path.GetFileName(f.AbsolutePath), func, line, message);
337             }
338 #endif
339         }
340     }
341 }