Use "file://" prefix to make a uri
[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             Print(Interop.Dlog.LogPriority.DLOG_DEBUG, tag, message, file, func, line);
31         }
32
33         /// <summary>
34         /// Prints a log message with the VERBOSE priority.
35         /// </summary>
36         /// <param name="tag">The tag name of the log message.</param>
37         /// <param name="message">The log message to print.</param>
38         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
39         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
40         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
41         public static void Verbose(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
42         {
43             Print(Interop.Dlog.LogPriority.DLOG_VERBOSE, tag, message, file, func, line);
44         }
45
46         /// <summary>
47         /// Prints a log message with the INFO priority.
48         /// </summary>
49         /// <param name="tag">The tag name of the log message.</param>
50         /// <param name="message">The log message to print.</param>
51         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
52         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
53         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
54         public static void Info(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
55         {
56             Print(Interop.Dlog.LogPriority.DLOG_INFO, tag, message, file, func, line);
57         }
58
59         /// <summary>
60         /// Prints a log message with the WARNING priority.
61         /// </summary>
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 caller function. This argument will be set automatically by the compiler.</param>
66         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
67         public static void Warn(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
68         {
69             Print(Interop.Dlog.LogPriority.DLOG_WARN, tag, message, file, func, line);
70         }
71
72         /// <summary>
73         /// Prints a log message with the ERROR priority.
74         /// </summary>
75         /// <param name="tag">The tag name of the log message.</param>
76         /// <param name="message">The log message to print.</param>
77         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
78         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
79         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
80         public static void Error(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
81         {
82             Print(Interop.Dlog.LogPriority.DLOG_ERROR, tag, message, file, func, line);
83         }
84
85         /// <summary>
86         /// Prints a log message with the FATAL priority.
87         /// </summary>
88         /// <param name="tag">The tag name of the log message.</param>
89         /// <param name="message">The log message to print.</param>
90         /// <param name="file">The source file path of the caller function. This argument will be set automatically by the compiler.</param>
91         /// <param name="func">The function name of caller function. This argument will be set automatically by the compiler.</param>
92         /// <param name="line">The line number of calling position. This argument will be set automatically by the compiler.</param>
93         public static void Fatal(string tag, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
94         {
95             Print(Interop.Dlog.LogPriority.DLOG_FATAL, tag, message, file, func, line);
96         }
97
98         private static void Print(Interop.Dlog.LogPriority priority, string tag, string message, string file, string func, int line)
99         {
100             if (String.IsNullOrEmpty(file))
101             {
102                 Interop.Dlog.Print(priority, tag, "%s", message);
103             }
104             else
105             {
106                 Uri f = new Uri("file://" + file);
107                 Interop.Dlog.Print(priority, tag, "%s: %s(%d) > %s", Path.GetFileName(f.AbsolutePath), func, line, message);
108             }
109         }
110     }
111 }