Remove NET45 project
[platform/core/csapi/tizen.git] / Tizen / 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
21 namespace Tizen
22 {
23     /// <summary>
24     /// Provides methods to print log messages to Tizen logging system.
25     /// </summary>
26     public static class Log
27     {
28         /// <summary>
29         /// Prints a log message with the DEBUG priority.
30         /// </summary>
31         /// <param name="tag">The tag name of the log message.</param>
32         /// <param name="message">The log message to print.</param>
33         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
34         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
35         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
36         public static void Debug(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
37         {
38             Print(Interop.Dlog.LogPriority.DLOG_DEBUG, tag, message, file, func, line);
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             Print(Interop.Dlog.LogPriority.DLOG_VERBOSE, tag, message, file, func, line);
52         }
53
54         /// <summary>
55         /// Prints a log message with the INFO priority.
56         /// </summary>
57         /// <param name="tag">The tag name of the log message.</param>
58         /// <param name="message">The log message to print.</param>
59         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
60         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
61         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
62         public static void Info(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
63         {
64             Print(Interop.Dlog.LogPriority.DLOG_INFO, tag, message, file, func, line);
65         }
66
67         /// <summary>
68         /// Prints a log message with the WARNING priority.
69         /// </summary>
70         /// <param name="tag">The tag name of the log message.</param>
71         /// <param name="message">The log message to print.</param>
72         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
73         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
74         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
75         public static void Warn(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
76         {
77             Print(Interop.Dlog.LogPriority.DLOG_WARN, tag, message, file, func, line);
78         }
79
80         /// <summary>
81         /// Prints a log message with the ERROR priority.
82         /// </summary>
83         /// <param name="tag">The tag name of the log message.</param>
84         /// <param name="message">The log message to print.</param>
85         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
86         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
87         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
88         public static void Error(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
89         {
90             Print(Interop.Dlog.LogPriority.DLOG_ERROR, tag, message, file, func, line);
91         }
92
93         /// <summary>
94         /// Prints a log message with the FATAL priority.
95         /// </summary>
96         /// <param name="tag">The tag name of the log message.</param>
97         /// <param name="message">The log message to print.</param>
98         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
99         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
100         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
101         public static void Fatal(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
102         {
103             Print(Interop.Dlog.LogPriority.DLOG_FATAL, tag, message, file, func, line);
104         }
105
106         private static void Print(Interop.Dlog.LogPriority priority, string tag, string message, string file, string func, int line)
107         {
108             if (String.IsNullOrEmpty(file))
109             {
110                 Interop.Dlog.Print(priority, tag, "%s", message);
111             }
112             else
113             {
114                 Uri f = new Uri("file://" + file);
115                 Interop.Dlog.Print(priority, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, message);
116             }
117         }
118     }
119 }