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