~eloaders/i-nex/I-Nex

« back to all changes in this revision

Viewing changes to src/i-nex/.src/Formatter.module

  • Committer: eloaders
  • Date: 2014-07-15 16:31:30 UTC
  • Revision ID: git-v1:64e92b39f32ea7a292985dee67d4c6de1333f9fa
Move src to I-Nex

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
' Gambas module file
2
 
 
3
 
' Copyright(C) 2011-2014, Michał Głowienka aka eloaders <eloaders@linux.pl>
4
 
'
5
 
' This program is free software; you can redistribute it and/or modify
6
 
' it under the terms of the GNU General Public License as published by
7
 
' the Free Software Foundation; either version 3 of the License, or
8
 
' (at your option) any later version.
9
 
'
10
 
' This program is distributed in the hope that it will be useful,
11
 
' but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
' GNU General Public License for more details.
14
 
'
15
 
' You should have received a copy of the GNU General Public License
16
 
' along with this program. If not, see <http://www.gnu.org/licenses/>.
17
 
 
18
 
Private Function GetCallLocation() As String
19
 
 
20
 
  Return System.Backtrace[3]
21
 
 
22
 
End
23
 
 
24
 
Private Function GetCallFile() As String
25
 
 
26
 
  Return Split(System.Backtrace[3], ".")[0]
27
 
 
28
 
End
29
 
 
30
 
Private Function GetCallFunction() As String
31
 
 
32
 
  Return Split(System.Backtrace[3], ".")[1]
33
 
 
34
 
End
35
 
 
36
 
Private Function GetCallLine() As String
37
 
 
38
 
  Return Split(System.Backtrace[3], ".")[2]
39
 
 
40
 
End
41
 
 
42
 
'' cal
43
 
Public Function _call(sMessage As String, sFormat As String, iLevel As Integer) As String
44
 
 
45
 
  Dim sName As String
46
 
 
47
 
  If String.InStr(sFormat, "$(message)") > 0 Then
48
 
    sFormat = Replace$(sFormat, "$(message)", sMessage)
49
 
  Endif
50
 
 
51
 
  If String.InStr(sFormat, "$(callLocation)") > 0 Then
52
 
    sFormat = Replace$(sFormat, "$(callLocation)", GetCallLocation())
53
 
  Endif
54
 
 
55
 
  If String.InStr(sFormat, "$(callLine)") > 0 Then
56
 
    sFormat = Replace$(sFormat, "$(callLine)", GetCallLine())
57
 
  Endif
58
 
 
59
 
  If String.InStr(sFormat, "$(callFile)") > 0 Then
60
 
    sFormat = Replace$(sFormat, "$(callFile)", GetCallFile())
61
 
  Endif
62
 
 
63
 
  If String.InStr(sFormat, "$(callFunction)") > 0 Then
64
 
    sFormat = Replace$(sFormat, "$(callFunction)", GetCallFunction())
65
 
  Endif
66
 
 
67
 
  If String.InStr(sFormat, "$(now)") > 0 Then
68
 
    sFormat = Replace$(sFormat, "$(now)", CStr(Now))
69
 
  Endif
70
 
 
71
 
  If String.InStr(sFormat, "$(date)") > 0 Then
72
 
    sFormat = Replace$(sFormat, "$(date)", CStr(Date(Now)))
73
 
  Endif
74
 
 
75
 
  If String.InStr(sFormat, "$(time)") > 0 Then
76
 
    sFormat = Replace$(sFormat, "$(time)", CStr(Time(Now)))
77
 
  Endif
78
 
 
79
 
  If String.InStr(sFormat, "$(ptimer)") > 0 Then
80
 
    sFormat = Replace$(sFormat, "$(ptimer)", CStr(Timer))
81
 
  Endif
82
 
 
83
 
  If String.InStr(sFormat, "$(ptimerint)") > 0 Then
84
 
    sFormat = Replace$(sFormat, "$(ptimerint)", CStr(Int(Timer)))
85
 
  Endif
86
 
 
87
 
  If String.InStr(sFormat, "$(levelno)") > 0 Then
88
 
    sFormat = Replace$(sFormat, "$(levelno)", CStr(iLevel))
89
 
  Endif
90
 
 
91
 
  If String.InStr(sFormat, "$(levelname)") > 0 Then
92
 
    Select Case iLevel
93
 
 
94
 
      Case Logger.Critical
95
 
        sName = "CRITICAL"
96
 
 
97
 
      Case Logger.Error
98
 
        sName = "ERROR"
99
 
 
100
 
      Case Logger.Warning
101
 
        sName = "WARNING"
102
 
 
103
 
      Case Logger.Info
104
 
        sName = "INFO"
105
 
 
106
 
      Case Logger.Debug
107
 
        sName = "DEBUG"
108
 
 
109
 
    End Select
110
 
 
111
 
    sFormat = Replace$(sFormat, "$(levelname)", sName)
112
 
 
113
 
  Endif
114
 
 
115
 
  If String.InStr(sFormat, "$(version)") > 0 Then
116
 
    sFormat = Replace$(sFormat, "$(version)", Application.Version)
117
 
  Endif
118
 
 
119
 
  If String.InStr(sFormat, "$(gbversion)") > 0 Then
120
 
    sFormat = Replace$(sFormat, "$(gbversion)", System.FullVersion)
121
 
  Endif
122
 
 
123
 
  If String.InStr(sFormat, "$(host)") > 0 Then
124
 
    sFormat = Replace$(sFormat, "$(host)", System.Host)
125
 
  Endif
126
 
 
127
 
  If String.InStr(sFormat, "$(pid)") > 0 Then
128
 
    sFormat = Replace$(sFormat, "$(pid)", CStr(Application.Id))
129
 
  Endif
130
 
 
131
 
  Return sFormat
132
 
 
133
 
End