~ubuntu-branches/ubuntu/trusty/smuxi/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/ServiceStack/src/ServiceStack.Interfaces/Logging/Support/Logging/ConsoleLogger.cs

  • Committer: Package Import Robot
  • Author(s): Mirco Bauer
  • Date: 2013-05-25 22:11:31 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20130525221131-nd2mc0kzubuwyx20
Tags: 0.8.11-1
* [22d13d5] Imported Upstream version 0.8.11
* [6d2b95a] Refreshed patches
* [89eb66e] Added ServiceStack libraries to smuxi-engine package
* [848ab10] Enable Campfire engine
* [c6dbdc7] Always build db4o for predictable build result
* [13ec489] Exclude OS X specific libraries from dh_clideps

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
 
 
3
namespace ServiceStack.Logging.Support.Logging
 
4
{
 
5
    /// <summary>
 
6
    /// Default logger is to Console.WriteLine
 
7
    /// 
 
8
    /// Made public so its testable
 
9
    /// </summary>
 
10
    public class ConsoleLogger : ILog
 
11
    {
 
12
        const string DEBUG = "DEBUG: ";
 
13
        const string ERROR = "ERROR: ";
 
14
        const string FATAL = "FATAL: ";
 
15
        const string INFO = "INFO: ";
 
16
        const string WARN = "WARN: ";
 
17
 
 
18
        /// <summary>
 
19
        /// Initializes a new instance of the <see cref="DebugLogger"/> class.
 
20
        /// </summary>
 
21
        /// <param name="type">The type.</param>
 
22
        public ConsoleLogger(string type)
 
23
        {
 
24
        }
 
25
 
 
26
        /// <summary>
 
27
        /// Initializes a new instance of the <see cref="DebugLogger"/> class.
 
28
        /// </summary>
 
29
        /// <param name="type">The type.</param>
 
30
                public ConsoleLogger(Type type)
 
31
        {
 
32
        }
 
33
 
 
34
        #region ILog Members
 
35
 
 
36
                public bool IsDebugEnabled { get { return true; } }
 
37
                
 
38
                /// <summary>
 
39
        /// Logs the specified message.
 
40
        /// </summary>
 
41
        /// <param name="message">The message.</param>
 
42
        /// <param name="exception">The exception.</param>
 
43
        private static void Log(object message, Exception exception)
 
44
        {
 
45
            string msg = message == null ? string.Empty : message.ToString();
 
46
            if (exception != null)
 
47
            {
 
48
                msg += ", Exception: " + exception.Message;
 
49
            }
 
50
            Console.WriteLine(msg);
 
51
        }
 
52
 
 
53
        /// <summary>
 
54
        /// Logs the format.
 
55
        /// </summary>
 
56
        /// <param name="message">The message.</param>
 
57
        /// <param name="args">The args.</param>
 
58
        private static void LogFormat(object message, params object[] args)
 
59
        {
 
60
            string msg = message == null ? string.Empty : message.ToString();
 
61
            Console.WriteLine(msg, args);
 
62
        }
 
63
 
 
64
        /// <summary>
 
65
        /// Logs the specified message.
 
66
        /// </summary>
 
67
        /// <param name="message">The message.</param>
 
68
        private static void Log(object message)
 
69
        {
 
70
            string msg = message == null ? string.Empty : message.ToString();
 
71
            Console.WriteLine(msg);
 
72
        }
 
73
 
 
74
        public void Debug(object message, Exception exception)
 
75
        {
 
76
            Log(DEBUG + message, exception);
 
77
        }
 
78
 
 
79
        public void Debug(object message)
 
80
        {
 
81
            Log(DEBUG + message);
 
82
        }
 
83
 
 
84
        public void DebugFormat(string format, params object[] args)
 
85
        {
 
86
            LogFormat(DEBUG + format, args);
 
87
        }
 
88
 
 
89
        public void Error(object message, Exception exception)
 
90
        {
 
91
            Log(ERROR + message, exception);
 
92
        }
 
93
 
 
94
        public void Error(object message)
 
95
        {
 
96
            Log(ERROR + message);
 
97
        }
 
98
 
 
99
        public void ErrorFormat(string format, params object[] args)
 
100
        {
 
101
            LogFormat(ERROR + format, args);
 
102
        }
 
103
 
 
104
        public void Fatal(object message, Exception exception)
 
105
        {
 
106
            Log(FATAL + message, exception);
 
107
        }
 
108
 
 
109
        public void Fatal(object message)
 
110
        {
 
111
            Log(FATAL + message);
 
112
        }
 
113
 
 
114
        public void FatalFormat(string format, params object[] args)
 
115
        {
 
116
            LogFormat(FATAL + format, args);
 
117
        }
 
118
 
 
119
        public void Info(object message, Exception exception)
 
120
        {
 
121
            Log(INFO + message, exception);
 
122
        }
 
123
 
 
124
        public void Info(object message)
 
125
        {
 
126
            Log(INFO + message);
 
127
        }
 
128
 
 
129
        public void InfoFormat(string format, params object[] args)
 
130
        {
 
131
            LogFormat(INFO + format, args);
 
132
        }
 
133
 
 
134
        public void Warn(object message, Exception exception)
 
135
        {
 
136
            Log(WARN + message, exception);
 
137
        }
 
138
 
 
139
        public void Warn(object message)
 
140
        {
 
141
            Log(WARN + message);
 
142
        }
 
143
 
 
144
        public void WarnFormat(string format, params object[] args)
 
145
        {
 
146
            LogFormat(WARN + format, args);
 
147
        }
 
148
 
 
149
        #endregion
 
150
    }
 
151
}