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
89243ee8
Kaydet (Commit)
89243ee8
authored
May 14, 2019
tarafından
Ali
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added send method and ServerException for LogServer
üst
1217d8ba
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
190 additions
and
10 deletions
+190
-10
LogServer.js
lib/src/LogServer.js
+35
-3
Logger.js
lib/src/Logger.js
+69
-1
package-lock.json
package-lock.json
+13
-0
ServerException.ts
src/Exceptions/ServerException.ts
+10
-0
LogServer.ts
src/LogServer.ts
+42
-5
Logger.ts
src/Logger.ts
+21
-1
No files found.
lib/src/LogServer.js
Dosyayı görüntüle @
89243ee8
"use strict"
;
var
__assign
=
(
this
&&
this
.
__assign
)
||
function
()
{
__assign
=
Object
.
assign
||
function
(
t
)
{
for
(
var
s
,
i
=
1
,
n
=
arguments
.
length
;
i
<
n
;
i
++
)
{
...
...
@@ -9,30 +10,61 @@ var __assign = (this && this.__assign) || function () {
};
return
__assign
.
apply
(
this
,
arguments
);
};
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
var
ServerException_1
=
require
(
"./Exceptions/ServerException"
);
/**
* @class LogServer
* @description This class helps to debug messages send to the server.
*/
var
LogServer
=
/** @class */
(
function
()
{
/**
*
* @param serverSettings Log backend settings as a parameter
*/
function
LogServer
(
serverSettings
)
{
/**
* Log Backend Settings
*/
this
.
settings
=
{
useServer
:
false
,
endPoint
:
''
,
method
:
'POST'
,
headers
:
{},
body
:
{}
};
this
.
settings
=
__assign
({},
serverSettings
);
if
(
this
.
settings
.
useServer
)
{
if
(
!
this
.
settings
.
endPoint
)
{
throw
new
ServerException_1
.
default
(
"Endpoint must be defined!"
);
}
}
}
LogServer
.
prototype
.
sendToLogServer
=
function
(
sendBody
)
{
/**
* @description private function to send data to log backend
* @function sendToServer
* @param sendBody
*/
LogServer
.
prototype
.
sendToServer
=
function
(
sendBody
)
{
var
endPoint
=
this
.
settings
.
endPoint
;
var
headers
=
this
.
settings
.
headers
;
var
body
=
this
.
settings
.
body
;
var
method
=
this
.
settings
.
method
;
fetch
(
endPoint
,
{
return
fetch
(
endPoint
,
{
method
:
method
,
headers
:
__assign
({},
headers
),
body
:
body
body
:
JSON
.
stringify
(
__assign
({},
body
,
sendBody
))
});
};
/**
* @description public function to send data to log backend. If useServer flag is not true, data will not send to the server.
* @function sendToLogServer
* @param sendBody
*/
LogServer
.
prototype
.
sendToLogServer
=
function
(
sendBody
)
{
if
(
this
.
settings
.
useServer
)
{
this
.
sendToServer
(
sendBody
);
}
};
return
LogServer
;
}());
exports
.
default
=
LogServer
;
lib/src/Logger.js
Dosyayı görüntüle @
89243ee8
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
var
LogTypes_1
=
require
(
"./LogTypes"
);
var
LogServer_1
=
require
(
"./LogServer"
);
/**
* @description Logger class. This class will have logging functions
* @class Logger
...
...
@@ -8,10 +9,25 @@ var LogTypes_1 = require("./LogTypes");
var
Logger
=
/** @class */
(
function
()
{
function
Logger
(
logConfig
)
{
this
.
config
=
{
server
:
{}
useServer
:
false
,
endPoint
:
''
,
method
:
'POST'
,
headers
:
{},
body
:
{}
};
this
.
config
=
logConfig
;
this
.
server
=
new
LogServer_1
.
default
(
this
.
config
.
server
);
}
/**
* @description Send extra fields to the log backend
* @function send
* @param sendBody Extra body field
* @example
* loggerInstance.send({ pageUrl: 'test', 'time': '12:30' })
*/
Logger
.
prototype
.
send
=
function
(
sendBody
)
{
return
this
.
server
.
sendToLogServer
(
sendBody
);
};
/**
* @description Debug Level Message
* @function debug
...
...
@@ -64,6 +80,58 @@ var Logger = /** @class */ (function () {
var
levelName
=
LogTypes_1
.
Levels
.
GET
(
logCode
);
console
.
log
(
logCode
,
levelName
);
};
/**
* @description Runtime errors, for example when parseInt or toFixed errors work wrong
* @function error
* @param message any type of message
* @param context Context will use to handle params. For example user IP address, username etc.
* @example
* loggerInstance.error('Error User', { username: 'John' })
*/
Logger
.
prototype
.
error
=
function
(
message
,
context
)
{
var
logCode
=
LogTypes_1
.
default
.
ERROR
;
var
levelName
=
LogTypes_1
.
Levels
.
GET
(
logCode
);
console
.
log
(
logCode
,
levelName
);
};
/**
* @description Components unavailable or unexpected exceptions
* @function critical
* @param message any type of message
* @param context Context will use to handle params. For example user IP address, username etc.
* @example
* loggerInstance.critical('Critical message User', { username: 'John' })
*/
Logger
.
prototype
.
critical
=
function
(
message
,
context
)
{
var
logCode
=
LogTypes_1
.
default
.
CRITICAL
;
var
levelName
=
LogTypes_1
.
Levels
.
GET
(
logCode
);
console
.
log
(
logCode
,
levelName
);
};
/**
* @description Action must be taken immediately.
* @function alert
* @param message any type of message
* @param context Context will use to handle params. For example user IP address, username etc.
* @example
* loggerInstance.alert('Alert message User', { username: 'John' })
*/
Logger
.
prototype
.
alert
=
function
(
message
,
context
)
{
var
logCode
=
LogTypes_1
.
default
.
ALERT
;
var
levelName
=
LogTypes_1
.
Levels
.
GET
(
logCode
);
console
.
log
(
logCode
,
levelName
);
};
/**
* @description System is unusable
* @function emergency
* @param message any type of message
* @param context Context will use to handle params. For example user IP address, username etc.
* @example
* loggerInstance.emergency('Emergency message User', { username: 'John' })
*/
Logger
.
prototype
.
emergency
=
function
(
message
,
context
)
{
var
logCode
=
LogTypes_1
.
default
.
EMERGENCY
;
var
levelName
=
LogTypes_1
.
Levels
.
GET
(
logCode
);
console
.
log
(
logCode
,
levelName
);
};
return
Logger
;
}());
exports
.
default
=
Logger
;
package-lock.json
0 → 100644
Dosyayı görüntüle @
89243ee8
{
"name"
:
"nisanci"
,
"version"
:
"1.0.0"
,
"lockfileVersion"
:
1
,
"requires"
:
true
,
"dependencies"
:
{
"@types/node"
:
{
"version"
:
"12.0.1"
,
"resolved"
:
"https://registry.npmjs.org/@types/node/-/node-12.0.1.tgz"
,
"integrity"
:
"sha512-7sy7DKVJrCTbaAERJZq/CU12bzdmpjRr321/Ne9QmzhB3iZ//L16Cizcni5hHNbANxDbxwMb9EFoWkM8KPkp0A=="
}
}
}
src/Exceptions/ServerException.ts
0 → 100644
Dosyayı görüntüle @
89243ee8
class
ServerException
extends
Error
{
constructor
(
message
)
{
super
();
this
.
message
=
message
this
.
name
=
"ServerException"
}
}
export
default
ServerException
\ No newline at end of file
src/LogServer.ts
Dosyayı görüntüle @
89243ee8
import
ServerException
from
"./Exceptions/ServerException"
;
/**
* @class LogServer
* @description This class helps to debug messages send to the server.
*/
class
LogServer
{
/**
* Log Backend Settings
*/
private
settings
:
any
=
{
useServer
:
false
,
endPoint
:
''
,
method
:
'POST'
,
headers
:
{},
body
:
{}
}
/**
*
* @param serverSettings Log backend settings as a parameter
*/
constructor
(
serverSettings
:
any
)
{
this
.
settings
=
{
...
serverSettings
}
if
(
this
.
settings
.
useServer
)
{
if
(
!
this
.
settings
.
endPoint
)
{
throw
new
ServerException
(
"Endpoint must be defined!"
);
}
}
}
protected
sendToLogServer
(
sendBody
?:
any
)
{
/**
* @description private function to send data to log backend
* @function sendToServer
* @param sendBody
*/
private
sendToServer
(
sendBody
?:
any
)
{
const
endPoint
=
this
.
settings
.
endPoint
const
headers
=
this
.
settings
.
headers
const
body
=
this
.
settings
.
body
const
method
=
this
.
settings
.
method
fetch
(
endPoint
,
{
return
fetch
(
endPoint
,
{
method
:
method
,
headers
:
{
...
headers
},
body
:
body
body
:
JSON
.
stringify
({
...
body
,
...
sendBody
})
})
}
}
\ No newline at end of file
/**
* @description public function to send data to log backend. If useServer flag is not true, data will not send to the server.
* @function sendToLogServer
* @param sendBody
*/
public
sendToLogServer
(
sendBody
?:
any
)
{
if
(
this
.
settings
.
useServer
)
{
this
.
sendToServer
(
sendBody
)
}
}
}
export
default
LogServer
\ No newline at end of file
src/Logger.ts
Dosyayı görüntüle @
89243ee8
import
LogTypes
,
{
Levels
}
from
'./LogTypes'
import
LogServer
from
'./LogServer'
/**
* @description Logger class. This class will have logging functions
...
...
@@ -7,11 +8,30 @@ import LogTypes, { Levels } from './LogTypes'
class
Logger
{
private
config
:
any
=
{
server
:
{}
useServer
:
false
,
endPoint
:
''
,
method
:
'POST'
,
headers
:
{},
body
:
{}
}
private
server
:
LogServer
constructor
(
logConfig
?:
any
)
{
this
.
config
=
logConfig
this
.
server
=
new
LogServer
(
this
.
config
.
server
)
}
/**
* @description Send extra fields to the log backend
* @function send
* @param sendBody Extra body field
* @example
* loggerInstance.send({ pageUrl: 'test', 'time': '12:30' })
*/
public
send
(
sendBody
?:
any
)
{
return
this
.
server
.
sendToLogServer
(
sendBody
)
}
/**
...
...
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