Kaydet (Commit) 3e35a20f authored tarafından Ali's avatar Ali

very first commit message

üst
lib/*.js
lib/*.map
tests/*.js
tests/*.map
node_modules/*
logs
*.log
npm-debug.log*
\ No newline at end of file
# Nisanci
Nisanci is yet another logger
**Status**: Under Development
\ No newline at end of file
import Logger from './src/Logger'
import LogTypes, { Levels } from './src/LogTypes'
export {
Logger,
LogTypes,
Levels
}
// Inspired: https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md
\ No newline at end of file
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/**
* @class LogServer
* @description This class helps to debug messages send to the server.
*/
var LogServer = /** @class */ (function () {
function LogServer(serverSettings) {
this.settings = {
endPoint: '',
method: 'POST',
headers: {},
body: {}
};
this.settings = __assign({}, serverSettings);
}
LogServer.prototype.sendToLogServer = function (sendBody) {
var endPoint = this.settings.endPoint;
var headers = this.settings.headers;
var body = this.settings.body;
var method = this.settings.method;
fetch(endPoint, {
method: method,
headers: __assign({}, headers),
body: body
});
};
return LogServer;
}());
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @description Log Levels are explained by RFC 5424
* @see https://tools.ietf.org/html/rfc5424
* @enum LogTypes
*/
var LogTypes;
(function (LogTypes) {
/**
* @description System is unusable
* @type {integer}
*/
LogTypes[LogTypes["EMERGENCY"] = 600] = "EMERGENCY";
/**
* @description Action must be taken immediately.
* * Example: Server returned 500, browser doesn't support function etc. This should trigger backend alerts.
* @type {integer}
*/
LogTypes[LogTypes["ALERT"] = 550] = "ALERT";
/**
* @description Critical conditions
* * Example: Components unavailable or unexpected exceptions
* @type {integer}
*/
LogTypes[LogTypes["CRITICAL"] = 500] = "CRITICAL";
/**
* @description Error conditions
* * Example: Runtime errors, for example when parseInt or toFixed errors work wrong
* @type {integer}
*/
LogTypes[LogTypes["ERROR"] = 400] = "ERROR";
/**
* @description Warning conditions
* * Example: You can use to show deprecated messages, old API or functions
* @type {integer}
*/
LogTypes[LogTypes["WARNING"] = 300] = "WARNING";
/**
* @description Normal but significant condition
* * Example: Normal but significant events
* @type {integer}
*/
LogTypes[LogTypes["NOTICE"] = 250] = "NOTICE";
/**
* @description Informational messages
* * Example: Interesting behavioral events. For example, event firing, dom changing etc.
* @type {integer}
*/
LogTypes[LogTypes["INFO"] = 200] = "INFO";
/**
* @description Debug-level messages
* * Example: Detailed debug information
* @type {integer}
*/
LogTypes[LogTypes["DEBUG"] = 100] = "DEBUG";
})(LogTypes || (LogTypes = {}));
var Levels = /** @class */ (function () {
function Levels() {
}
Levels.GET = function (logType) {
switch (logType) {
case 100:
return "DEBUG";
break;
case 200:
return "INFO";
break;
case 250:
return "NOTICE";
break;
case 300:
return "WARNING";
break;
case 400:
return "ERROR";
break;
case 500:
return "CRITICAL";
break;
case 550:
return "ALERT";
break;
case 600:
return "EMERGENCY";
break;
default:
break;
}
};
return Levels;
}());
exports.Levels = Levels;
exports.default = LogTypes;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var LogTypes_1 = require("./LogTypes");
/**
* @description Logger class. This class will have logging functions
* @class Logger
*/
var Logger = /** @class */ (function () {
function Logger(logConfig) {
this.config = {
server: {}
};
this.config = logConfig;
}
/**
* @description Debug Level Message
* @function debug
* @param message any type of message
* @param context Context will use to handle params. For example user IP address, username etc.
* @example
* loggerInstance.debug('Debug User', { username: 'John' })
*/
Logger.prototype.debug = function (message, context) {
var logCode = LogTypes_1.default.DEBUG;
var levelName = LogTypes_1.Levels.GET(logCode);
console.log(logCode, levelName);
};
/**
* @description Informational messages
* @function info
* @param message any type of message
* @param context Context will use to handle params. For example user IP address, username etc.
* @example
* loggerInstance.info('Info User', { username: 'John' })
*/
Logger.prototype.info = function (message, context) {
var logCode = LogTypes_1.default.INFO;
var levelName = LogTypes_1.Levels.GET(logCode);
console.log(logCode, levelName);
};
/**
* @description Normal but significant condition
* @function notice
* @param message any type of message
* @param context Context will use to handle params. For example user IP address, username etc.
* @example
* loggerInstance.notice('Notice User', { username: 'John' })
*/
Logger.prototype.notice = function (message, context) {
var logCode = LogTypes_1.default.NOTICE;
var levelName = LogTypes_1.Levels.GET(logCode);
console.log(logCode, levelName);
};
/**
* @description You can use to show deprecated messages, old API or functions
* @function warning
* @param message any type of message
* @param context Context will use to handle params. For example user IP address, username etc.
* @example
* loggerInstance.warning('Warning User', { username: 'John' })
*/
Logger.prototype.warning = function (message, context) {
var logCode = LogTypes_1.default.WARNING;
var levelName = LogTypes_1.Levels.GET(logCode);
console.log(logCode, levelName);
};
return Logger;
}());
exports.default = Logger;
{
"name": "nisanci",
"version": "1.0.0",
"description": "Nisanci is yet another logger",
"main": "index.js",
"scripts": {
"build": "tsc",
"dev": "node tests/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"logger",
"typescript",
"javascript"
],
"author": "Ali GOREN",
"license": "MIT"
}
/**
* @class LogServer
* @description This class helps to debug messages send to the server.
*/
class LogServer {
private settings: any = {
endPoint: '',
method: 'POST',
headers: {},
body: {}
}
constructor(serverSettings: any) {
this.settings = { ...serverSettings }
}
protected sendToLogServer(sendBody?: any) {
const endPoint = this.settings.endPoint
const headers = this.settings.headers
const body = this.settings.body
const method = this.settings.method
fetch(endPoint, {
method: method,
headers: {
...headers
},
body: body
})
}
}
\ No newline at end of file
/**
* @description Log Levels are explained by RFC 5424
* @see https://tools.ietf.org/html/rfc5424
* @enum LogTypes
*/
enum LogTypes {
/**
* @description System is unusable
* @type {integer}
*/
EMERGENCY = 600,
/**
* @description Action must be taken immediately.
* * Example: Server returned 500, browser doesn't support function etc. This should trigger backend alerts.
* @type {integer}
*/
ALERT = 550,
/**
* @description Critical conditions
* * Example: Components unavailable or unexpected exceptions
* @type {integer}
*/
CRITICAL = 500,
/**
* @description Error conditions
* * Example: Runtime errors, for example when parseInt or toFixed errors work wrong
* @type {integer}
*/
ERROR = 400,
/**
* @description Warning conditions
* * Example: You can use to show deprecated messages, old API or functions
* @type {integer}
*/
WARNING = 300,
/**
* @description Normal but significant condition
* * Example: Normal but significant events
* @type {integer}
*/
NOTICE = 250,
/**
* @description Informational messages
* * Example: Interesting behavioral events. For example, event firing, dom changing etc.
* @type {integer}
*/
INFO = 200,
/**
* @description Debug-level messages
* * Example: Detailed debug information
* @type {integer}
*/
DEBUG = 100,
}
class Levels {
public static GET(logType: LogTypes): string {
switch (logType) {
case 100:
return "DEBUG"
break;
case 200:
return "INFO"
break;
case 250:
return "NOTICE"
break;
case 300:
return "WARNING"
break;
case 400:
return "ERROR"
break;
case 500:
return "CRITICAL"
break;
case 550:
return "ALERT"
break;
case 600:
return "EMERGENCY"
break;
default:
break;
}
}
}
export {
Levels
}
export default LogTypes;
\ No newline at end of file
import LogTypes, { Levels } from './LogTypes'
/**
* @description Logger class. This class will have logging functions
* @class Logger
*/
class Logger {
private config: any = {
server: {}
}
constructor(logConfig?: any) {
this.config = logConfig
}
/**
* @description Debug Level Message
* @function debug
* @param message any type of message
* @param context Context will use to handle params. For example user IP address, username etc.
* @example
* loggerInstance.debug('Debug User', { username: 'John' })
*/
debug(message: string, context: any) {
const logCode = LogTypes.DEBUG
const levelName = Levels.GET(logCode)
console.log(logCode, levelName)
}
/**
* @description Informational messages
* @function info
* @param message any type of message
* @param context Context will use to handle params. For example user IP address, username etc.
* @example
* loggerInstance.info('Info User', { username: 'John' })
*/
info(message: string, context: any) {
const logCode = LogTypes.INFO
const levelName = Levels.GET(logCode)
console.log(logCode, levelName)
}
/**
* @description Normal but significant condition
* @function notice
* @param message any type of message
* @param context Context will use to handle params. For example user IP address, username etc.
* @example
* loggerInstance.notice('Notice User', { username: 'John' })
*/
notice(message: string, context: any) {
const logCode = LogTypes.NOTICE
const levelName = Levels.GET(logCode)
console.log(logCode, levelName)
}
/**
* @description You can use to show deprecated messages, old API or functions
* @function warning
* @param message any type of message
* @param context Context will use to handle params. For example user IP address, username etc.
* @example
* loggerInstance.warning('Warning User', { username: 'John' })
*/
warning(message: string, context: any) {
const logCode = LogTypes.WARNING
const levelName = 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' })
*/
error(message: string, context: any) {
const logCode = LogTypes.ERROR
const levelName = 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' })
*/
critical(message: string, context: any) {
const logCode = LogTypes.CRITICAL
const levelName = 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' })
*/
alert(message: string, context: any) {
const logCode = LogTypes.ALERT
const levelName = 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' })
*/
emergency(message: string, context: any) {
const logCode = LogTypes.EMERGENCY
const levelName = Levels.GET(logCode)
console.log(logCode, levelName)
}
}
export default Logger
\ No newline at end of file
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es5", "es6", "dom"],
"outDir": "lib"
},
"include": [
"**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment