Comparing version 1.4.2 to 1.5.0
95
index.js
'use strict'; | ||
var logUtil = require('./logUtil'); | ||
var linesUtil = require('./linesUtil'); | ||
var config = require('./config'); | ||
var config = require('./src/config'); | ||
var loggingFunctions = require('./src/loggingFunctions'); | ||
var m = { | ||
////////////////// | ||
// main methods // | ||
////////////////// | ||
function getLogLevel() { | ||
var level = process.env.LOG_LEVEL; | ||
if (level) { | ||
level = config._logLevels[level.toLowerCase()].level; | ||
} | ||
return level || config._logLevels.trace.level; | ||
} | ||
// default | ||
d: function() { | ||
logUtil.logWithColor(config.colors.logs.default, arguments); | ||
}, | ||
// success | ||
s: function() { | ||
logUtil.logWithColor(config.colors.logs.success, arguments); | ||
}, | ||
// warning | ||
w: function() { | ||
logUtil.logWithColor(config.colors.logs.warning, arguments); | ||
}, | ||
// err | ||
e: function() { | ||
logUtil.logWithColor(config.colors.logs.error, arguments); | ||
}, | ||
// highlight | ||
h: function() { | ||
logUtil.logWithColor(config.colors.logs.highlight, arguments); | ||
}, | ||
//info | ||
i: function() { | ||
logUtil.logWithColor(config.colors.logs.info, arguments); | ||
}, | ||
//trace: | ||
t: function() { | ||
logUtil.logTraceWithColor(config.colors.logs.trace, arguments); | ||
}, | ||
function meetsLogLevelRequirement(loggerLevel) { | ||
return loggerLevel <= getLogLevel(); | ||
} | ||
/////////// | ||
// lines // | ||
/////////// | ||
// default | ||
line: function(char, length) { | ||
linesUtil.logLine(char, length, this.e, this.w); | ||
}, | ||
// default - another | ||
dline: function(char, length) { | ||
linesUtil.logLine(char, length, this.e, this.w); | ||
}, | ||
// success | ||
sline: function(char, length) { | ||
linesUtil.logLine(char, length, this.e, this.w, config.colors.logs.success); | ||
}, | ||
// warning | ||
wline: function(char, length) { | ||
linesUtil.logLine(char, length, this.e, this.w, config.colors.logs.warning); | ||
}, | ||
// error | ||
eline: function(char, length) { | ||
linesUtil.logLine(char, length, this.e, this.w, config.colors.logs.error); | ||
}, | ||
// highlight | ||
hline: function(char, length) { | ||
linesUtil.logLine(char, length, this.e, this.w, config.colors.logs.highlight); | ||
function createLogFunction(loggingFunctionParams) { | ||
if (loggingFunctionParams.type === config._types.log) { | ||
return function() { | ||
if (meetsLogLevelRequirement(loggingFunctionParams.level)) { | ||
loggingFunctionParams.logFunction(loggingFunctionParams.color, arguments); | ||
} | ||
}; | ||
} else if (loggingFunctionParams.type === config._types.line) { | ||
return function(char, length) { | ||
if (meetsLogLevelRequirement(loggingFunctionParams.level)) { | ||
loggingFunctionParams.logFunction(char, length, m.e, m.w, loggingFunctionParams.color); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
var m = {}; | ||
loggingFunctions.forEach(function(loggingFunctionParams) { | ||
m[loggingFunctionParams.functionName] = createLogFunction(loggingFunctionParams); | ||
}); | ||
module.exports = m; |
@@ -11,4 +11,13 @@ { | ||
"trace": ["green"] | ||
}, | ||
"lines": { | ||
"default": ["white"], | ||
"success": ["bold", "green"], | ||
"warning": ["bgYellow", "black"], | ||
"error": ["bgRed", "white"], | ||
"highlight": ["bgCyan", "black"], | ||
"info": ["bold", "cyan"], | ||
"trace": ["green"] | ||
} | ||
} | ||
} |
{ | ||
"name": "lme", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "Simply and beautifully log to console.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
161
README.md
@@ -1,2 +0,3 @@ | ||
[![Build Status](https://travis-ci.org/vajahath/lme.svg?branch=stable)](https://travis-ci.org/vajahath/lme) | ||
[![Build Status](https://travis-ci.org/vajahath/lme.svg?branch=master)](https://travis-ci.org/vajahath/lme) | ||
[![Known Vulnerabilities](https://snyk.io/test/npm/lme/badge.svg)](https://snyk.io/test/npm/lme) | ||
@@ -13,17 +14,20 @@ ![](https://raw.githubusercontent.com/vajahath/lme/stable/media/logo.png) | ||
``` | ||
:dizzy: _This package is built from ground up with simplicity in mind. Best configuration ships with this package. i.e, You don't have to configure anything extra to start using this package. But if you need something unique, or if color of your terminal background contradicts with this package's colors (causing accessibility issues), or if you are a kind of unicorn, you have wonderful options to adjust them here. And this package is bound to strictly follow semantic versioning._ | ||
> **v1.4** is out. **What's new?**<br> | ||
> **-** Now [define your own color schemes](#custom-color-schemes)! <br> | ||
> **v1.5** is out. **What's new?**<br> | ||
> **-** Set environment variable to [adjust level of logging](https://github.com/vajahath/lme/wiki/Adjust-Logging-Level).<br> | ||
> **-** Define your own [color schemes for lines](https://github.com/vajahath/lme/wiki/Custom-Color-Schemes) <br> | ||
> **-** Define your own [color schemes for texts](https://github.com/vajahath/lme/wiki/Custom-Color-Schemes) <br> | ||
> **-** Multiple argumnets support: _`lme.s("hi", "hello")`_ <br> | ||
> **-** Stability and performance improvements. | ||
## Why `lme` *( logme )* | ||
- Clean and semantically focused. | ||
- Consistent design for errors, warnings, successes etc. | ||
- Simpler to use than `console.log()` or even `console.log(chalk.red("hi"));` | ||
- **Draw lines** with just a single function, [`lme.line()`](#drawing-lines-with-lmeline). | ||
- **[Draw lines](#drawing-lines-with-lmeline)** with just a single function, `lme.line()`. | ||
- Automatically expands `objects` and `arrays`. So that, you don't have to use `JSON.stringify()` anymore. | ||
- **[Define your own color schemes](#custom-color-schemes)** with `lmeconfig.json` file. | ||
- Clean and semantically focused. | ||
- **[Define your own color schemes](https://github.com/vajahath/lme/wiki/Custom-Color-Schemes)** with `lmeconfig.json` file. | ||
- [Set environment variables to adjust logging level](https://github.com/vajahath/lme/wiki/Adjust-Logging-Level). | ||
- Actively maintained. | ||
- Consistent design for errors, warnings, successes etc. | ||
@@ -123,103 +127,11 @@ ![](https://raw.githubusercontent.com/vajahath/lme/stable/media/windows-object.png) | ||
## Custom Color Schemes | ||
You can add your own color scheme to your project and make it unique! It's simple. Here is how: | ||
# Advanced fearures | ||
1. Go to your application root directory | ||
2. Create an `lmeconfig.json` file there with the following content. | ||
3. Restart your application. | ||
- **[Custom Color Schemes](https://github.com/vajahath/lme/wiki/Custom-Color-Schemes):** Define your own color schems. | ||
- **[Adjust logging level](https://github.com/vajahath/lme/wiki/Adjust-Logging-Level):** Set environment variable to adjust logging levels. | ||
### Content of `lmeconfig.json` | ||
Basically, this file describes your configurations that the `lme` should follow. If no such valid files are found at the application root, it will follow the default configurations. | ||
Below is an example `lmeconfig.json`: | ||
```json | ||
{ | ||
"colors": { | ||
"logs": { | ||
"default": ["red"], | ||
"error": ["bgRed", "cyan"] | ||
} | ||
} | ||
} | ||
``` | ||
This configuration will overwrite the default configurations. | ||
So, | ||
- when you use `lme.d("hi")` next time, it will be in **red**. | ||
- when you use `lme.e("hi")` next time, text-color will be **cyan** and background-color will be **red**. | ||
- the changes will also be reflected in corresponding line functions. In this case, `lme.line()`, `lme.dline()`, `lme.eline()`. | ||
- Nothing else will be changed. | ||
### Possible values in `lmeconfig.json` | ||
#### Styling | ||
| Available colors | Background colors | Modifiers | | ||
| :----------------- | :------------------- | :-------------------------------------- | | ||
| `black` | `bgBlack` | `reset` | | ||
| `red` | `bgRed` | `bold` | | ||
| `green` | `bgGreen` | `dim` | | ||
| `yellow` | `bgYellow` | `italic` (not widely supported) | | ||
| `blue` | `bgMagenta` | `underline` | | ||
| `magenta` | `bgCyan` | `inverse` | | ||
| `cyan` | `bgWhite` | `hidden` | | ||
| `white` | `bgBlue` |`strikethrough` (not widely supported) | | ||
| `gray` | | ||
You can specify multiple styles for a text by mentioning it as an `Array`. | ||
Example: | ||
```json | ||
{ | ||
"colors": { | ||
"logs": { | ||
"error": ["bgRed", "cyan", "bold"] | ||
} | ||
} | ||
} | ||
``` | ||
#### Properties and its jobs | ||
Below is the list of all properties and its jobs that the `lmeconfig.json` file can have. | ||
| Properties | what it does? | | ||
| :----------------------- | :--------------- | | ||
| `colors.logs.default` | styles `lme.d()` | | ||
| `colors.logs.success` | styles `lme.s()` | | ||
| `colors.logs.error` | styles `lme.e()` | | ||
| `colors.logs.warning` | styles `lme.w()` | | ||
| `colors.logs.highlight` | styles `lme.h()` | | ||
| `colors.logs.info` | styles `lme.i()` | | ||
| `colors.logs.trace` | styles `lme.t()` | | ||
### Default configurations | ||
You can find default configurations in | ||
```bash | ||
./node_modules/lme/lmeDefaultConfig.json | ||
``` | ||
> **Note:** It is not recommended to alter this file. If you need to change it, adding an `lmeconfig.json` file at the application root directory is equivalent and safe. | ||
here is an example: | ||
```json | ||
{ | ||
"colors": { | ||
"logs": { | ||
"default": ["white"], | ||
"success": ["bold", "green"], | ||
"warning": ["bgYellow", "black"], | ||
"error": ["bgRed", "white"], | ||
"highlight": ["bgCyan", "black"], | ||
"info": ["bold", "cyan"], | ||
"trace": ["green"] | ||
} | ||
} | ||
} | ||
``` | ||
<br> | ||
<br> | ||
[Wiki](https://github.com/vajahath/lme/wiki)<br> | ||
More configurations are on its way.<br> | ||
If you wish to file any feature/bugs, mention it on [issues](https://github.com/vajahath/lme/issues). | ||
<br> | ||
@@ -237,6 +149,15 @@ | ||
#### Loves lme? _tell your friends.._ | ||
#### Loves lme? :heart: | ||
tell your friends.. :two_men_holding_hands: <br> | ||
[star this project on Github](https://github.com/vajahath/lme) :star: | ||
## Change log | ||
- **v1.5.0** (6th March 2017) | ||
- Support for [custom separate color schemes for line and text](https://github.com/vajahath/lme/wiki/Custom-Color-Schemes). | ||
- [Adjust log level](https://github.com/vajahath/lme/wiki/Adjust-Logging-Level) with environment variable. | ||
- Better directory organization | ||
- Better documentation (including [Wiki](https://github.com/vajahath/lme/wiki)) | ||
- Adds vulnerability test. | ||
- Stability improvements | ||
- **v1.4.1, v1.4.2** | ||
@@ -249,32 +170,6 @@ - Patch: Excluding an unnecessary folder -> reduces package size. | ||
- Stability and performance improvements. | ||
- **v1.3.1, v1.3.2** | ||
+ Docs update. | ||
- **v1.3.0** | ||
+ Internal code structure redesigned for better flexibility. (*thanks [@demacdonald](https://github.com/demacdonald) for [#4](https://github.com/vajahath/lme/pull/4)*) | ||
+ This package is now capable of having more features in a well structured manner. Developers can now add new features with ease. *We invite you to do so*. | ||
- **v1.2.0** | ||
+ Adds support for `trace`. | ||
+ Adds support for `info`. (*thanks [@amandeepmittal](https://github.com/amandeepmittal)*) | ||
+ Bug fixes | ||
* `line()` functions now support older versions of node. | ||
* Changed some colors for better accessibility on Windows and Linux machines. | ||
* Fixed some minor quirks. | ||
- **v1.1.3** | ||
+ bug fixes | ||
+ docs update | ||
- **v1.1.2** | ||
+ bug fixes | ||
+ docs update | ||
- **v1.1.1** | ||
+ bug fixes | ||
+ docs update | ||
- **v1.1.0** | ||
+ adds support for drawing lines | ||
+ docs update | ||
- **versions < 1.1.0** | ||
+ adds support for semantic outputs. | ||
+ bug fixes | ||
+ doc updates | ||
[See detailed change log](https://github.com/vajahath/lme/wiki/Change-Log) | ||
## License | ||
MIT © [Vajahath Ahmed](https://mycolorpad.blogspot.in) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10
228
17187
172
1
1