Basename bug fixed
[platform/core/dotnet/launcher.git] / Tizen.Runtime / Tizen.Runtime / 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.InteropServices;
20 using System.Runtime.CompilerServices;
21
22 namespace Tizen.Runtime
23 {
24 #if CLOG
25     internal static class Log
26     {
27         static void Print(string tag, string message)
28         {
29             string[] lines = message.Split('\r');
30             foreach (string line in lines)
31             {
32                 Console.WriteLine($"{tag} : {message}");
33             }
34         }
35
36         public static void Debug(string tag, string message)
37         {
38             Print($"D/{tag}", message);
39         }
40
41         public static void Info(string tag, string message)
42         {
43             Print($"I/{tag}", message);
44         }
45
46         public static void Error(string tag, string message)
47         {
48             Print($"E/{tag}", message);
49         }
50     }
51 #endif
52     internal static class ALog
53     {
54         const string Library = "libdlog.so.0";
55         const string TAG = "DOTNET_LAUNCHER";
56
57         public static void Debug(string message,
58                 [CallerFilePath] string file = "",
59                 [CallerMemberName] string func = "",
60                 [CallerLineNumber] int line = 0)
61         {
62             Print(LogPriority.DLOG_DEBUG, TAG, message, file, func, line);
63         }
64
65         public static void Info(string message,
66                 [CallerFilePath] string file = "",
67                 [CallerMemberName] string func = "",
68                 [CallerLineNumber] int line = 0)
69         {
70             Print(LogPriority.DLOG_DEBUG, TAG, message, file, func, line);
71         }
72
73         public static void Error(string message,
74                 [CallerFilePath] string file = "",
75                 [CallerMemberName] string func = "",
76                 [CallerLineNumber] int line = 0)
77         {
78             Print(LogPriority.DLOG_DEBUG, TAG, message, file, func, line);
79         }
80
81         internal enum LogPriority
82         {
83             DLOG_UNKNOWN = 0,
84             DLOG_DEFAULT,
85             DLOG_VERBOSE,
86             DLOG_DEBUG,
87             DLOG_INFO,
88             DLOG_WARN,
89             DLOG_ERROR,
90             DLOG_FATAL,
91             DLOG_SILENT,
92             DLOG_PRIO_MAX,
93         }
94
95         private static void Print(LogPriority priority, string tag, string message, string file, string func, int line)
96         {
97             FileInfo finfo = new FileInfo(file);
98             Print(priority, tag, "%s: %s(%d) > %s", finfo.Name, func, line, message); 
99         }
100
101         [DllImportAttribute(Library, EntryPoint = "dlog_print")]
102         internal static extern int Print(LogPriority prio, string tag, string fmt, string file, string func, int line, string msg);
103     }
104 }