logginglog 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Wilco Joosen
2
+
3
+ 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:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ 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.
package/README.md CHANGED
@@ -1,21 +1,49 @@
1
- # LOGGINGLOG
1
+ # Logginglog
2
2
 
3
- > Prachtige logger voor console logging
3
+ > Powerful and colorful logging for Node.js — console or file-based!
4
4
 
5
- ## Installatie
6
- ```shell
5
+ ## Installation
6
+
7
+ ```bash
7
8
  npm install logginglog
8
9
  ```
9
10
 
10
- ## Gebruik
11
- ```shell
12
- var logginglog = require('./logginglog');
13
- var logger = logginglog.createLogger();
14
- var colors = logginglog.colors();
15
- logger.log('Algemeen');
16
- logger.info('Info');
11
+ ## Usage
12
+ ```js
13
+ import logginglog from 'logginglog';
14
+
15
+ const logger = logginglog.createLogger();
16
+ logger.log('Hello world!');
17
+ logger.info('Information');
17
18
  logger.warn('Warning');
18
- logger.error('Foutmelding');
19
- var melding = logginglog.makeLogger('Zelfgemaakt', colors.italic);
20
- melding('Zelfgemaakte melding');
19
+ logger.error('Error message');
20
+ ```
21
+
22
+ ## Custom logger with color and styles
23
+ ```js
24
+ const custom = logginglog.customLogger('MyLogger', {
25
+ color: 'blue',
26
+ styles: ['bold', 'underline']
27
+ });
28
+
29
+ custom('A custom log line');
21
30
  ```
31
+
32
+ ### Supported styles:
33
+ - `bold`
34
+ - `italic`
35
+ - `underline`
36
+ - `dim`
37
+
38
+ ### Supported colors:
39
+ All chalk-extra colors, such as red, green, blue, cyan, etc.
40
+
41
+ ## Log to file
42
+ ```js
43
+ const fileLogger = logginglog.createFileLogger('mylogs.txt');
44
+ fileLogger.log('This line will be written to the file.');
45
+ ```
46
+
47
+ ## License
48
+
49
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ declare module 'logginglog' {
2
+ import type chalk from 'chalk-extra';
3
+
4
+ type Style = 'bold' | 'italic' | 'underline' | 'dim';
5
+ type Color = keyof typeof chalk;
6
+
7
+ export interface Logger {
8
+ log(msg: string): void;
9
+ info(msg: string): void;
10
+ warn(msg: string): void;
11
+ error(msg: string): void;
12
+ }
13
+
14
+ export function createLogger(): Logger;
15
+
16
+ export function customLogger(
17
+ name: string,
18
+ options: { color: Color; styles?: Style[] }
19
+ ): (msg: string) => void;
20
+
21
+ export function createFileLogger(path?: string): Logger;
22
+
23
+ const logginglog: {
24
+ createLogger: typeof createLogger;
25
+ customLogger: typeof customLogger;
26
+ createFileLogger: typeof createFileLogger;
27
+ };
28
+
29
+ export default logginglog;
30
+ }
package/logginglog.js CHANGED
@@ -1,17 +1,83 @@
1
- const logging = require('./logging');
2
- const make = require('./makelogger');
3
- const colors = require('./colors');
4
- const random = require('./random');
5
- const logginglog = exports;
1
+ import chalk from "chalk-extra";
2
+ import dayjs from "dayjs";
3
+ import { resolve } from "path";
4
+ import { appendFileSync } from "fs";
5
+ import localizedFormat from 'dayjs/plugin/localizedFormat.js';
6
+ import 'dayjs/locale/nl.js';
7
+
8
+ const log = console.log;
9
+ let logginglog = {};
10
+
11
+ // DayJS settings
12
+ dayjs.extend(localizedFormat);
13
+ dayjs.locale('nl');
14
+ const formatTime = (datum) => dayjs(datum).format('D MMM YYYY HH:mm:ss');
15
+
16
+ logginglog.customLogger = function (name, { color, styles = [] }) {
17
+ const base = chalk[color];
18
+ if (typeof base !== 'function') {
19
+ throw new Error(`Invalid color: ${color}`);
20
+ }
21
+
22
+ const allowedStyles = ['bold', 'underline', 'italic', 'dim'];
23
+ let styling = base;
24
+ for (let style of styles) {
25
+ if (!allowedStyles.includes(style)) {
26
+ throw new Error(`Invalid style: ${style}`);
27
+ }
28
+ if (typeof styling[style] === 'function') {
29
+ styling = styling[style];
30
+ }
31
+ }
32
+
33
+ return (msg) => {
34
+ const prefix = `${formatTime(new Date())}, ${name} >>`;
35
+ log(`${styling(prefix)} ${chalk.underline(msg)}`);
36
+ };
37
+ };
38
+
39
+ logginglog.createFileLogger = function (file = 'log.txt') {
40
+ const fullPath = resolve(file);
41
+ const append = (type, msg) => {
42
+ const line = `${formatTime(new Date())}, ${type} >> ${msg}\n`;
43
+ appendFileSync(fullPath, line);
44
+ };
45
+
46
+ return {
47
+ log(msg) {
48
+ append('Log', msg);
49
+ },
50
+ info(msg) {
51
+ append('Info', msg);
52
+ },
53
+ warn(msg) {
54
+ append('Warning', msg);
55
+ },
56
+ error(msg) {
57
+ append('Error', msg);
58
+ }
59
+ };
60
+ };
6
61
 
7
62
  logginglog.createLogger = function () {
8
- return logging();
9
- }
10
- logginglog.makeLogger = function (name, color) {
11
- return make(name, color);
12
- }
13
- logginglog.colors = function () {
14
- return colors;
15
- }
16
-
17
- module.exports = logginglog;
63
+ return {
64
+ log(msg) {
65
+ let prefix = formatTime(new Date()) + ', Log >> ';
66
+ log(chalk.green(prefix) + chalk.underline(msg));
67
+ },
68
+ info(msg) {
69
+ let prefix = formatTime(new Date()) + ', Info >> ';
70
+ log(chalk.blue(prefix) + chalk.underline(msg));
71
+ },
72
+ warn(msg) {
73
+ let prefix = formatTime(new Date()) + ', Warning >> ';
74
+ log(chalk.yellow(prefix) + chalk.underline(msg));
75
+ },
76
+ error(msg) {
77
+ let prefix = formatTime(new Date()) + ', Error >> ';
78
+ log(chalk.red.bold(prefix) + chalk.underline(msg));
79
+ }
80
+ };
81
+ };
82
+
83
+ export default logginglog;
package/package.json CHANGED
@@ -1,15 +1,30 @@
1
1
  {
2
2
  "name": "logginglog",
3
- "version": "1.0.0",
4
- "description": "Een eenvoudige logging module",
3
+ "version": "2.0.0",
4
+ "description": "Een logging module voor alle mensen die gewoon snel een logger willen hebben",
5
+ "keywords": [
6
+ "logging",
7
+ "console"
8
+ ],
9
+ "homepage": "https://github.com/computer-wilco/logginglog#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/computer-wilco/logginglog/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/computer-wilco/logginglog.git"
16
+ },
17
+ "license": "MIT",
18
+ "author": "Wilco Joosen",
19
+ "type": "module",
5
20
  "main": "logginglog.js",
21
+ "types": "index.d.ts",
6
22
  "scripts": {
7
- "test": "node logginglog.js"
23
+ "test": "node logginglog.js",
24
+ "update": "npx -y Jelmerro/nus"
8
25
  },
9
- "author": "Wilco Joosen",
10
- "license": "ISC",
11
26
  "dependencies": {
12
- "colors": "^1.4.0",
13
- "moment": "^2.30.1"
27
+ "chalk-extra": "0.1.2",
28
+ "dayjs": "1.11.13"
14
29
  }
15
30
  }
package/colors.js DELETED
@@ -1,83 +0,0 @@
1
- var styles = {};
2
-
3
- var codes = {
4
- reset: [0, 0],
5
-
6
- bold: [1, 22],
7
- dim: [2, 22],
8
- italic: [3, 23],
9
- underline: [4, 24],
10
- inverse: [7, 27],
11
- hidden: [8, 28],
12
- strikethrough: [9, 29],
13
-
14
- black: [30, 39],
15
- red: [31, 39],
16
- green: [32, 39],
17
- yellow: [33, 39],
18
- blue: [34, 39],
19
- magenta: [35, 39],
20
- cyan: [36, 39],
21
- white: [37, 39],
22
- gray: [90, 39],
23
- grey: [90, 39],
24
-
25
- brightRed: [91, 39],
26
- brightGreen: [92, 39],
27
- brightYellow: [93, 39],
28
- brightBlue: [94, 39],
29
- brightMagenta: [95, 39],
30
- brightCyan: [96, 39],
31
- brightWhite: [97, 39],
32
-
33
- bgBlack: [40, 49],
34
- bgRed: [41, 49],
35
- bgGreen: [42, 49],
36
- bgYellow: [43, 49],
37
- bgBlue: [44, 49],
38
- bgMagenta: [45, 49],
39
- bgCyan: [46, 49],
40
- bgWhite: [47, 49],
41
- bgGray: [100, 49],
42
- bgGrey: [100, 49],
43
-
44
- bgBrightRed: [101, 49],
45
- bgBrightGreen: [102, 49],
46
- bgBrightYellow: [103, 49],
47
- bgBrightBlue: [104, 49],
48
- bgBrightMagenta: [105, 49],
49
- bgBrightCyan: [106, 49],
50
- bgBrightWhite: [107, 49],
51
-
52
- blackBG: [40, 49],
53
- redBG: [41, 49],
54
- greenBG: [42, 49],
55
- yellowBG: [43, 49],
56
- blueBG: [44, 49],
57
- magentaBG: [45, 49],
58
- cyanBG: [46, 49],
59
- whiteBG: [47, 49],
60
-
61
- zebra: ['zebra'],
62
- trap: ['trap'],
63
- random: ['random'],
64
- rainbow: ['rainbow'],
65
- };
66
-
67
- Object.keys(codes).forEach(function(key) {
68
- var val = codes[key];
69
- if (val[0] === 'zebra'){
70
- var style = styles[key] = val;
71
- } else if (val[0] === 'trap'){
72
- var style = styles[key] = val;
73
- } else if (val[0] === 'random'){
74
- var style = styles[key] = val;
75
- } else if (val[0] === 'rainbow'){
76
- var style = styles[key] = val;
77
- } else {
78
- var code = '\u001b[' + val[0] + 'm';
79
- var style = styles[key] = code;
80
- }
81
- });
82
-
83
- module.exports = styles;
package/logging.js DELETED
@@ -1,26 +0,0 @@
1
- var moment = require('moment');
2
- var colors = require('colors');
3
- module.exports = function () {
4
- moment.locale('nl');
5
- this.log = function (msg) {
6
- var prefixString = moment().format('lll') + ', Log >> ';
7
- console.log(prefixString.green + msg.underline);
8
- };
9
-
10
- this.info = function (msg) {
11
- var prefixString = moment().format('lll') + ', Info >> ';
12
- console.log(prefixString.blue + msg.underline);
13
- };
14
-
15
- this.warn = function (msg) {
16
- var prefixString = moment().format('lll') + ', Warning >> ';
17
- console.info(prefixString.yellow + msg.underline);
18
- };
19
-
20
- this.error = function (msg) {
21
- var prefixString = moment().format('lll') + ', Error >> ';
22
- console.error(prefixString.bold.red + msg.underline);
23
- };
24
-
25
- return this;
26
- };
package/makelogger.js DELETED
@@ -1,37 +0,0 @@
1
- const moment = require('moment');
2
- const colors = require('colors');
3
- const reset = '\x1B[0m';
4
-
5
- function makeLogger(name, color) {
6
- moment.locale('nl');
7
- if (color == 'zebra') {
8
- function make(msg) {
9
- var prefixString = moment().format('lll') + `, ${name} >> `;
10
- console.error(prefixString.zebra + msg.underline);
11
- }
12
- } else if (color == 'trap') {
13
- function make(msg) {
14
- var prefixString = moment().format('lll') + `, ${name} >> `;
15
- console.error(prefixString.trap + msg.underline);
16
- }
17
- } else if (color == 'random') {
18
- function make(msg) {
19
- var prefixString = moment().format('lll') + `, ${name} >> `;
20
- console.error(prefixString.random + msg.underline);
21
- }
22
- } else if (color == 'rainbow') {
23
- function make(msg) {
24
- var prefixString = moment().format('lll') + `, ${name} >> `;
25
- console.error(prefixString.rainbow + msg.underline);
26
- }
27
- } else {
28
- function make(msg) {
29
- var prefixString = moment().format('lll') + `, ${name} >> `;
30
- console.error(color + prefixString + reset + msg.underline);
31
- }
32
- }
33
-
34
- return make;
35
- }
36
-
37
- module.exports = makeLogger;
package/random.js DELETED
@@ -1,5 +0,0 @@
1
- module.exports = function (min, max) {
2
- const minCeiled = Math.ceil(min);
3
- const maxFloored = Math.floor(max);
4
- return Math.floor(Math.random() * (maxFloored - minCeiled + 1)) + minCeiled;
5
- }