Package Exports
- logifys
- logifys/log.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (logifys) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
LOGIFYS
Installation
yarn add logifys
or
npm install logifys
Usage
To use LOGIFYS, simply import the package and call the log
function:
const log = require('logifys');
log('This is an info message', { font: 'bold', color: 'green', file: './log.txt' });
log('This is a warning message', { font: 'italic', backgroundColor: 'yellow', color: 'black', size: 'small', file: './log.txt' });
log('This is an error message', { font: 'underline', color: 'red', size: 'large', file: './log.txt' });
Features
LOGIFYS makes logging easier and nicer to look at with its extensive selection of fonts and colors.
Colors
LOGIFYS supports the following colors:
- Red,
- Blue,
- Green,
- Yellow,
- Black,
- Cyan,
- Magenta,
- White,
- Lime,
- Brown,
- Pink,
- Gray,
- Purple,
- Orange
Background Colors
LOGIFYS supports the following background colors:
- Red,
- Blue,
- Green,
- Yellow,
- Black,
- Cyan,
- Magenta,
- White,
- Lime,
- Brown,
- Pink,
- Gray,
- Purple,
- Orange
Size
LOGIFYS supports the following sizes:
- Large,
- Normal,
- Small
Fonts
LOGIFYS supports the following fonts:
- Bold,
- Underline,
- Italic.
Example
Here is a simple proof of concept for LOGIFYS:
const log = require('logifys');
var points = new Array(100);
for (var i = 0; i < 100; i++) {
points[i] = i + 1;
}
for (var i = 0; i < points.length; i++) {
log(points[i], { font: 'bold', color: 'magenta' });
}
This code will produce the following output:
Logging
Here is an example of how the logging to .txt works:
const log = require('logifys');
log('This is an example of logging...', { font: 'bold', color: 'red', file: './log.txt' });
This code will produce the following output:
This code will result it being logged in a .txt file as shown:
Real World Usage
Here is an example of how you might use Logifys in a real world scenario:
const log = require('logifys');
const fs = require('fs');
const https = require('https');
// Your code to fetch data from an API
https.get('https://jsonplaceholder.typicode.com/posts', (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const posts = JSON.parse(data);
log(`Successfully fetched ${posts.length} posts`, { color: 'green', file: './log.txt' });
} catch (error) {
log(`Error fetching posts: ${error}`, { color: 'red', file: './log.txt' });
}
});
});
// Your code to write to a file
fs.writeFile('./notes.txt', 'Remember to buy milk', (error) => {
if (error) {
log(`Error writing to file: ${error}`, { color: 'red', file: './log.txt' });
} else {
log(`Successfully wrote to file`, { color: 'green', file: './log.txt' });
}
});
Web Development Example
Here is an example of how you might use Logifys in a web development scenario:
const log = require('logifys');
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.listen(port, () => {
log(`Server is listening on port ${port}`, { font: 'bold', color: 'green' });
});
app.get('/', (req, res) => {
log('Received a request to the root endpoint', { font: 'italic', color: 'blue' });
res.send('Welcome to the Express server!');
});
app.use((error, req, res, next) => {
log(`Error: ${error.message}`, { font: 'underline', color: 'red' });
res.status(500).send('An error occurred, please try again later.');
});