Skip to content

Commit

Permalink
feat(logger): added setloglevel and getloglevel methods
Browse files Browse the repository at this point in the history
in order to easily set log level of the library
  • Loading branch information
LCluber committed Sep 25, 2019
1 parent 5fe2e58 commit 7376865
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 52 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ static HTTP.OPTIONS( url: string, responseType: ResponseType ): Promise<Response
static HTTP.TRACE( url: string, responseType: ResponseType ): Promise<ResponseDataType> {}
static HTTP.PATCH( url: string, responseType: ResponseType, data: DataType ): Promise<ResponseDataType> {}

// Log levels from @lcluber Mouette.js dependency
type LevelName = "info" | "trace" | "warn" | "error" | "off";
static HTTP.setLogLevel(name: LevelName): LevelName {}
static HTTP.getLogLevel(): LevelName {}

static HTTP.get.setHeaders(headers: HTTPHeaders): void {}
static HTTP.get.getHeaders(): HTTPHeaders {}

Expand Down
4 changes: 4 additions & 0 deletions dist/aias.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
*
* https://github.com/LCluber/Aias.js
*/
import { LevelName } from "@lcluber/mouettejs";


export declare class HTTP {
private static log;
static setLogLevel(name: LevelName): LevelName;
static getLogLevel(): LevelName;
static get: Method;
static head: Method;
static post: Method;
Expand Down
90 changes: 41 additions & 49 deletions dist/aias.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,6 @@
var Aias = (function (exports) {
'use strict';

/* MIT License
Copyright (c) 2009 Ludovic CLUBER
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
https://github.com/LCluber/Ch.js
*/
function isObject(object) {
return object !== null && typeof object === "object" && !isArray(object);
}

function isArray(array) {
return array !== null && array.constructor === Array;
}

function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}

function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}

/** MIT License
*
* Copyright (c) 2015 Ludovic CLUBER
Expand Down Expand Up @@ -152,11 +116,20 @@ var Aias = (function (exports) {
this.messages = [];
this.name = name;
this.messages = [];
this._level = level;
this.level = level;
}

var _proto2 = Group.prototype;

_proto2.setLevel = function setLevel(name) {
this.level = LEVELS.hasOwnProperty(name) ? LEVELS[name] : this.level;
return this.getLevel();
};

_proto2.getLevel = function getLevel() {
return this.level.name;
};

_proto2.info = function info(message) {
this.log(LEVELS.info, message);
};
Expand All @@ -177,21 +150,11 @@ var Aias = (function (exports) {
var message = new Message(level, messageContent);
this.messages.push(message);

if (this._level.id <= message.id) {
if (this.level.id <= message.id) {
message.display(this.name);
}
};

_createClass(Group, [{
key: "level",
set: function set(name) {
this._level = LEVELS.hasOwnProperty(name) ? LEVELS[name] : this._level;
},
get: function get() {
return this._level.name;
}
}]);

return Group;
}();

Expand All @@ -216,7 +179,7 @@ var Aias = (function (exports) {
}

var group = _ref;
group.level = Logger.level.name;
group.setLevel(Logger.level.name);
}

return Logger.getLevel();
Expand Down Expand Up @@ -265,6 +228,26 @@ var Aias = (function (exports) {
Logger.level = LEVELS.error;
Logger.groups = [];

/* MIT License
Copyright (c) 2009 Ludovic CLUBER
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
https://github.com/LCluber/Ch.js
*/
function isObject(object) {
return object !== null && typeof object === "object" && !isArray(object);
}

function isArray(array) {
return array !== null && array.constructor === Array;
}

var Method =
/*#__PURE__*/
function () {
Expand Down Expand Up @@ -404,6 +387,14 @@ var Aias = (function (exports) {
function () {
function HTTP() {}

HTTP.setLogLevel = function setLogLevel(name) {
return this.log.setLevel(name);
};

HTTP.getLogLevel = function getLogLevel() {
return this.log.getLevel();
};

HTTP.GET = function GET(url, responseType) {
return this.get.call(url, responseType);
};
Expand Down Expand Up @@ -442,6 +433,7 @@ var Aias = (function (exports) {

return HTTP;
}();
HTTP.log = Logger.addGroup("Aias");
HTTP.get = new Method("GET", {
"Content-Type": "application/x-www-form-urlencoded"
});
Expand Down
2 changes: 1 addition & 1 deletion dist/aias.iife.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion dist/aias.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* https://github.com/LCluber/Aias.js
*/

import { isObject } from '@lcluber/chjs';
import { Logger } from '@lcluber/mouettejs';
import { isObject } from '@lcluber/chjs';

class Method {
constructor(method, defaultHeaders) {
Expand Down Expand Up @@ -156,6 +156,12 @@ class Method {
}

class HTTP {
static setLogLevel(name) {
return this.log.setLevel(name);
}
static getLogLevel() {
return this.log.getLevel();
}
static GET(url, responseType) {
return this.get.call(url, responseType);
}
Expand Down Expand Up @@ -184,6 +190,7 @@ class HTTP {
return this.patch.call(url, responseType, data);
}
}
HTTP.log = Logger.addGroup("Aias");
HTTP.get = new Method("GET", {
"Content-Type": "application/x-www-form-urlencoded"
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
],
"dependencies": {
"@lcluber/chjs": "2.6.2",
"@lcluber/mouettejs": "2.1.0"
"@lcluber/mouettejs": "2.2.1"
},
"devDependencies": {
"@commitlint/cli": "8.0.0",
Expand Down
11 changes: 11 additions & 0 deletions src/ts/aias.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { Logger, Group, LevelName } from "@lcluber/mouettejs";
import { Method } from "./method";
import { DataType, ResponseDataType, ResponseType } from "./types";

export class HTTP {
private static log: Group = Logger.addGroup("Aias");

public static setLogLevel(name: LevelName): LevelName {
return this.log.setLevel(name);
}

public static getLogLevel(): LevelName {
return this.log.getLevel();
}

public static get: Method = new Method("GET", {
"Content-Type": "application/x-www-form-urlencoded"
});
Expand Down

0 comments on commit 7376865

Please sign in to comment.