Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
N
nisanci
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Ali GOREN
nisanci
Commits
9ce1c190
Unverified
Kaydet (Commit)
9ce1c190
authored
May 16, 2019
tarafından
Ali GOREN
Kaydeden (comit)
GitHub
May 16, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #5 from aligoren/dev
Debug function works as expected now.
üst
b332cd74
2c2207cc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
11 deletions
+74
-11
Logger.ts
src/Logger.ts
+74
-11
No files found.
src/Logger.ts
Dosyayı görüntüle @
9ce1c190
...
...
@@ -2,6 +2,8 @@ import LogTypes, { Levels } from './LogTypes'
import
LogServer
from
'./LogServer'
import
Colors
from
'./Colors'
// inspired by: https://stackify.com/php-monolog-tutorial/
/**
* @description Logger class. This class will have logging functions
* @class Logger
...
...
@@ -10,13 +12,21 @@ class Logger {
private
isFormatted
:
boolean
private
formattedString
:
string
/**
* Singleton instance
*/
private
instance
:
Logger
private
config
:
any
=
{
useServer
:
false
,
endPoint
:
''
,
method
:
'POST'
,
headers
:
{},
body
:
{}
platform
:
'web'
,
server
:
{
useServer
:
false
,
endPoint
:
''
,
method
:
'POST'
,
headers
:
{},
body
:
{}
}
}
private
server
:
LogServer
...
...
@@ -26,12 +36,60 @@ class Logger {
this
.
server
=
new
LogServer
(
this
.
config
.
server
)
if
(
!
this
.
instance
)
{
this
.
instance
=
this
}
return
this
}
/**
* @description This helps to get date with time
* @function getDateWithTime
* @example this.getDateWithTime() // output: 2019-05-16 12:03:48
*/
private
getDateWithTime
()
{
const
date
=
(
new
Date
()).
toISOString
().
split
(
'T'
)[
0
]
const
time
=
(
new
Date
()).
toISOString
().
split
(
'T'
)[
1
].
slice
(
0
,
8
)
return
`
${
date
}
${
time
}
`
}
/**
* @description This method will help to customize log messages.
* @param formatStr - The string which will formatted
* @todo
*/
public
setFormat
(
formatStr
:
string
)
{
this
.
isFormatted
=
true
}
/**
* @description This method helps to prepare output message
* @param details - An object
* @example
*
* const messageData = {
* foregroundColor: colors.FgWhite,
* backgroundColor: colors.BgRed,
* levelName: levelName,
* message: message,
* reset: colors.Reset
* }
*/
private
setMessage
(
details
:
any
)
{
const
logDate
=
this
.
getDateWithTime
()
let
logString
=
`[
${
logDate
}
] -
${
details
.
foregroundColor
}${
details
.
backgroundColor
}
${
details
.
levelName
}
${
details
.
reset
}
- `
logString
+=
`
${
details
.
message
}
`
logString
=
logString
.
trim
()
return
logString
}
/**
* @description Debug Level Message
* @function debug
...
...
@@ -43,14 +101,19 @@ class Logger {
debug
(
message
:
string
,
context
:
any
)
{
const
logCode
=
LogTypes
.
DEBUG
const
levelName
=
Levels
.
GET
(
logCode
)
const
colors
=
Colors
.
Node
//Colors.GET('node')
const
colors
=
this
.
config
.
platform
==
"web"
?
Colors
[
"Web"
]
:
Colors
[
"Node"
]
const
messageData
=
{
foregroundColor
:
colors
.
FgWhite
,
backgroundColor
:
colors
.
BgRed
,
levelName
:
levelName
,
message
:
message
,
reset
:
colors
.
Reset
}
/**
* @todo This section will change. This needs formatted output
*/
console
.
log
(
logCode
,
levelName
)
console
.
log
(
`
${
colors
.
FgWhite
}${
colors
.
BgRed
}
%s`
,
`
${
levelName
}
`
,
colors
.
Reset
,
'-'
,
message
);
const
messageOutput
=
this
.
setMessage
(
messageData
)
console
.
log
(
messageOutput
)
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment