itivrutaha 2.0.8 → 2.0.12

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/README.md CHANGED
@@ -23,7 +23,7 @@
23
23
 
24
24
  **itivrutaha** is my first ever JavaScript (initially) project. It is a console logging module for Node.js to be used in CLIs, GUI desktop frameworks (like <a href="https://github.com/electron/electron" target="_blank" rel="noopener">Electron</a> & <a href="https://github.com/nodegui/nodegui" target="_blank" rel="noopener">NodeGUI</a>) and for web servers.
25
25
 
26
- > Tweet me <a target="_blank" rel="noopener" href="https://vas.cx/twitter">@vasanthdevelop</a>, I would love to know your opinion/experience on this project šŸ˜
26
+ > Tweet me <a target="_blank" rel="noopener" href="https://vas.cx/twitter">@vsnthdev</a>, I would love to know your opinion/experience on this project šŸ˜
27
27
 
28
28
  ## āš”ļø Features
29
29
 
@@ -68,7 +68,7 @@ To know more configuration options like **file logging**, **themes**, and **time
68
68
  * `npm run build` — Deletes existing build files & freshly compiles TypeScript code.
69
69
  * `npm run docs` — Deletes existing docs and freshly builds by reading code.
70
70
 
71
- **Note:** Run `node src/example.js` to test `itivrutaha` with the latest compiled code.
71
+ **Note:** Run `node examples/index.js` to test `itivrutaha` with the latest code.
72
72
 
73
73
  <!-- footer -->
74
74
 
@@ -76,7 +76,7 @@ To know more configuration options like **file logging**, **themes**, and **time
76
76
  > The **itivrutaha** project is released under the [MIT license](https://github.com/vasanthdeveloper/itivrutaha/blob/main/LICENSE.md). <br> Developed &amp; maintained By Vasanth Srivatsa. Copyright 2021 Ā© Vasanth Developer.
77
77
  <hr>
78
78
 
79
- > <a href="https://vasanth.tech" target="_blank" rel="noopener">vasanth.tech</a> &nbsp;&middot;&nbsp;
79
+ > <a href="https://vsnth.dev" target="_blank" rel="noopener">vsnth.dev</a> &nbsp;&middot;&nbsp;
80
80
  > YouTube <a href="https://vas.cx/videos" target="_blank" rel="noopener">@vasanthdeveloper</a> &nbsp;&middot;&nbsp;
81
- > Twitter <a href="https://vas.cx/twitter" target="_blank" rel="noopener">@vasanthdevelop</a> &nbsp;&middot;&nbsp;
81
+ > Twitter <a href="https://vas.cx/twitter" target="_blank" rel="noopener">@vsnthdev</a> &nbsp;&middot;&nbsp;
82
82
  > Discord <a href="https://vas.cx/discord" target="_blank" rel="noopener">Vasanth Developer</a>
package/dist/config.d.ts CHANGED
@@ -8,28 +8,28 @@ export declare enum typeCase {
8
8
  'title' = 2
9
9
  }
10
10
  export interface ConfigImpl {
11
- appName: string;
12
- bootLog: boolean;
13
- shutdownLog: boolean;
14
- clearOnSIGINT: boolean;
15
- quietIdentifier: Array<string>;
16
- verboseIdentifier: Array<string>;
11
+ appName?: string;
12
+ bootLog?: boolean;
13
+ shutdownLog?: boolean;
14
+ clearOnSIGINT?: boolean;
15
+ quietIdentifier?: Array<string>;
16
+ verboseIdentifier?: Array<string>;
17
17
  context?: {
18
18
  name: string;
19
19
  color: (str: string) => string;
20
20
  };
21
21
  theme?: {
22
- string: string;
23
- colored: boolean;
24
- boldType: boolean;
25
- typeCase: typeCase;
26
- timeFormat: string;
22
+ string?: string;
23
+ colored?: boolean;
24
+ boldType?: boolean;
25
+ typeCase?: typeCase;
26
+ timeFormat?: string;
27
27
  };
28
- logs: {
29
- dir: string;
30
- error: string;
31
- output: string;
32
- enable: boolean;
28
+ logs?: {
29
+ dir?: string;
30
+ error?: string;
31
+ output?: string;
32
+ enable?: boolean;
33
33
  };
34
34
  }
35
35
  export declare const configSchema: Joi.ObjectSchema<any>;
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "itivrutaha",
3
3
  "description": "( ą¤‡ą¤¤ą¤æą¤µą„ƒą¤¤ą„ą¤¤ą¤ƒ ) — Logging system āœ for Node.js with šŸ¬ theming and file šŸ—ƒ logging support.",
4
- "version": "2.0.8",
4
+ "version": "2.0.12",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "dist/itivrutaha.js",
8
- "homepage": "https://github.com/vasanthdeveloper/itivrutaha#readme",
9
- "bugs": "https://github.com/vasanthdeveloper/itivrutaha/issues",
8
+ "homepage": "https://github.com/vsnthdev/itivrutaha#readme",
9
+ "bugs": "https://github.com/vsnthdev/itivrutaha/issues",
10
10
  "author": {
11
- "name": "Vasanth Developer",
11
+ "name": "Vasanth Srivatsa",
12
12
  "email": "vasanth@vasanthdeveloper.com",
13
- "url": "https://vasanth.tech"
13
+ "url": "https://vsnth.dev"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "https://github.com/vasanthdeveloper/itivrutaha.git"
17
+ "url": "https://github.com/vsnthdev/itivrutaha.git"
18
18
  },
19
19
  "scripts": {
20
- "dev": "concurrently 'tsc --watch' 'nodemon'",
21
- "build": "rm -rf tsconfig.tsbuildinfo dist/ && tsc",
22
- "docs": "rm -rf docs/ && node scripts/docs.js"
20
+ "dev": "tsc --watch",
21
+ "build": "rimraf ./dist && tsc --incremental false",
22
+ "docs": "rimraf docs/ && node scripts/docs.js"
23
23
  },
24
24
  "keywords": [
25
25
  "cli",
@@ -33,41 +33,36 @@
33
33
  "command-line"
34
34
  ],
35
35
  "dependencies": {
36
- "chalk": "^4.1.1",
36
+ "chalk": "^5.0.0",
37
37
  "clear-terminal-line": "^0.0.1",
38
38
  "deepmerge": "^4.2.2",
39
39
  "del": "^6.0.0",
40
- "env-paths": "^2.2.1",
41
- "joi": "^17.4.1",
42
- "luxon": "^2.0.1",
40
+ "env-paths": "^3.0.0",
41
+ "joi": "^17.5.0",
42
+ "luxon": "^2.2.0",
43
43
  "mkdirp": "^1.0.4",
44
44
  "node-cleanup": "^2.1.2",
45
- "node-emoji": "^1.10.0",
46
- "read-pkg-up": "^8.0.0",
47
- "strip-ansi": "^7.0.0"
45
+ "node-emoji": "^1.11.0",
46
+ "read-pkg-up": "^9.0.0",
47
+ "strip-ansi": "^7.0.1"
48
48
  },
49
49
  "devDependencies": {
50
- "@types/chalk": "^2.2.0",
51
- "@types/deepmerge": "^2.2.0",
52
- "@types/del": "^4.0.0",
53
- "@types/env-paths": "^2.1.0",
54
- "@types/joi": "^17.2.3",
55
- "@types/luxon": "^1.27.1",
50
+ "@types/luxon": "^2.0.8",
56
51
  "@types/mkdirp": "^1.0.2",
57
- "@types/node": "^16.3.3",
58
- "@types/node-cleanup": "^2.1.1",
52
+ "@types/node": "^17.0.0",
53
+ "@types/node-cleanup": "^2.1.2",
59
54
  "@types/node-emoji": "^1.8.1",
60
- "@typescript-eslint/eslint-plugin": "^4.28.3",
61
- "@typescript-eslint/parser": "^4.28.3",
62
- "concurrently": "^6.2.0",
55
+ "@typescript-eslint/eslint-plugin": "^5.7.0",
56
+ "@typescript-eslint/parser": "^5.7.0",
57
+ "concurrently": "^6.4.0",
63
58
  "es-dirname": "^0.1.0",
64
- "eslint": "^7.30.0",
59
+ "eslint": "^8.4.1",
65
60
  "eslint-config-prettier": "^8.3.0",
66
- "eslint-plugin-import": "^2.23.4",
67
- "eslint-plugin-prettier": "^3.4.0",
61
+ "eslint-plugin-import": "^2.25.3",
62
+ "eslint-plugin-prettier": "^4.0.0",
68
63
  "eslint-plugin-simple-import-sort": "^7.0.0",
69
- "nodemon": "^2.0.12",
70
- "prettier": "^2.3.2",
71
- "typescript": "^4.3.5"
64
+ "prettier": "^2.5.1",
65
+ "rimraf": "^3.0.2",
66
+ "typescript": "^4.5.4"
72
67
  }
73
- }
68
+ }
package/.eslintrc.cjs DELETED
@@ -1,36 +0,0 @@
1
- /*
2
- * ESLint run control.
3
- * Created On 01 April 2021
4
- */
5
-
6
- module.exports = {
7
- parser: '@typescript-eslint/parser',
8
- plugins: ['prettier', 'simple-import-sort', '@typescript-eslint', 'import'],
9
- extends: [
10
- 'eslint:recommended',
11
- 'plugin:prettier/recommended',
12
- 'plugin:@typescript-eslint/recommended',
13
- ],
14
- env: {
15
- es2021: true,
16
- node: true,
17
- },
18
- parserOptions: {
19
- ecmaVersion: 12,
20
- sourceType: 'module',
21
- },
22
- settings: {
23
- 'import/extensions': ['.js'],
24
- },
25
- rules: {
26
- indent: ['error', 4],
27
- 'linebreak-style': ['error', 'unix'],
28
- quotes: ['off', 'single'],
29
- semi: ['error', 'never'],
30
- 'prettier/prettier': 'error',
31
- 'simple-import-sort/imports': 'error',
32
- 'sort-imports': 'off',
33
- 'import/order': 'off',
34
- '@typescript-eslint/no-explicit-any': 'off',
35
- },
36
- }
@@ -1,133 +0,0 @@
1
- <h5 align="center">
2
- <img src="https://github.com/vasanthdeveloper/itivrutaha/blob/designs/header.png?raw=true" alt="itivrutaha">
3
- </h5>
4
- <p align="center"><strong>( ą¤‡ą¤¤ą¤æą¤µą„ƒą¤¤ą„ą¤¤ą¤ƒ ) — Logging system āœ for Node.js with šŸ¬ theming and file šŸ—ƒ logging support.</strong></p>
5
- <p align="center">
6
- <a target="_blank" rel="noopener" href="https://www.npmjs.com/package/itivrutaha">
7
- <img src="https://img.shields.io/npm/v/itivrutaha.svg?style=flat-square" alt="">
8
- </a>
9
- <a target="_blank" rel="noopener" href="https://www.npmjs.com/package/itivrutaha?activeTab=versions">
10
- <img src="https://img.shields.io/npm/dm/itivrutaha.svg?style=flat-square" alt="">
11
- </a>
12
- <a href="https://github.com/vasanthdeveloper/itivrutaha/issues">
13
- <img src="https://img.shields.io/github/issues/vasanthdeveloper/itivrutaha.svg?style=flat-square" alt="">
14
- </a>
15
- <a href="https://github.com/vasanthdeveloper/itivrutaha/commits/main">
16
- <img src="https://img.shields.io/github/last-commit/vasanthdeveloper/itivrutaha.svg?style=flat-square"
17
- alt="">
18
- </a>
19
- </p>
20
- <br>
21
-
22
- ## šŸ›  Customization
23
-
24
- ```javascript
25
- import chalk from 'chalk'
26
- import itivrutaha from 'itivrutaha'
27
-
28
- // create a new instance of the logger
29
- const logger = await itivrutaha.createNewLogger({
30
- // The name of your app, if not provided
31
- // the value will be determined by reading
32
- // package.json of the above project.
33
- appName: null,
34
-
35
- // Whether to log when the logger is initialized.
36
- bootLog: true,
37
-
38
- // Whether to log when the Node.js process exits.
39
- // Logs when terminating gracefully, due to an error
40
- // or when POSIX signals are received.
41
- shutdownLog: true,
42
-
43
- // remove the "^CāŽ" after terminating the process
44
- // when Ctrl+C is pressed
45
- clearOnSIGINT: true,
46
-
47
- // Command-line arguments that suppress the output
48
- // to the console if found.
49
- quietIdentifier: ['--quiet', '-q'],
50
-
51
- // Command-line arguments that render verbose message
52
- // type to the console if found.
53
- verboseIdentifier: ['--verbose', '-v'],
54
-
55
- // Configuration for this particular logger.
56
- // Useful when application has multiple loggers.
57
- context: {
58
- // Name of the context, example "app", "api",
59
- // "bot", "server"...
60
- name: null,
61
-
62
- // Chalk color function for this context.
63
- color: chalk.blueBright,
64
- },
65
-
66
- // Configuration options related to rendering the
67
- // log messages to the console.
68
- theme: {
69
- // The theme string, that determines which variables
70
- // are to be rendered.
71
- string: `:time ${chalk.gray.dim('•')} :emoji :type :message`,
72
-
73
- // Whether to log colored output
74
- // or plain.
75
- colored: true,
76
-
77
- // Whether to render message type (":type" variable)
78
- // in bold.
79
- boldType: true,
80
-
81
- // The character casing to render message type or
82
- // the (":type" variable).
83
- typeCase: typeCase.lower,
84
-
85
- // Luxon time formatting used to render the
86
- // ":time" variable. See šŸ‘‡ for formatting guide
87
- // https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens
88
- timeFormat: 'HH:mm:ss dd-LL-yyyy',
89
- },
90
-
91
- logs: {
92
- // Whether to enable file logging or not.
93
- enable: false,
94
-
95
- // The directory where log files are saved.
96
- dir: null,
97
-
98
- // Filename for writing output (stdout)
99
- // logs.
100
- output: `output-${DateTime.local().toFormat('dd-LL-yyyy')}.log`,
101
-
102
- // Filename for writing error (stderr)
103
- // logs.
104
- error: `error-${DateTime.local().toFormat('dd-LL-yyyy')}.log`,
105
- },
106
- })
107
- ```
108
-
109
- ## āš”ļø Variables
110
-
111
- | Variable | Description |
112
- |-|-|
113
- | `:time` | The time of the log message. A [Luxon](https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens) format string can be given as `theme.timeFormat` to change the formatting. |
114
- | `:emoji` | Emoji according to the message type. |
115
- | `:message` | Log message in terminal's default color. |
116
- | `:node_path` | Full path to Node.js executable. |
117
- | `:type` | Message type (ie. info, warning, error, etc). |
118
- | `:script_path` | Full path of the Node.js entry JavaScript file. |
119
- | `:node_version` | Version of Node.js running. |
120
- | `:v8_version` | Version of V8 engine running along with Node.js. |
121
- | `:filename` | Filename of the Node.js entryfile. |
122
- | `:openssl_version` | Version of OpenSSL running along with Node.js. |
123
- | `:electron_version` | Version of Electron.js running. Returns `undefined` if not Electron. |
124
-
125
-
126
- ## šŸ“° License
127
- > The **itivrutaha** project is released under the [MIT license](https://github.com/vasanthdeveloper/itivrutaha/blob/main/LICENSE.md). <br> Developed &amp; maintained By Vasanth Srivatsa. Copyright 2021 Ā© Vasanth Developer.
128
- <hr>
129
-
130
- > <a href="https://vasanth.tech" target="_blank" rel="noopener">vasanth.tech</a> &nbsp;&middot;&nbsp;
131
- > YouTube <a href="https://vas.cx/videos" target="_blank" rel="noopener">@vasanthdeveloper</a> &nbsp;&middot;&nbsp;
132
- > Twitter <a href="https://vas.cx/twitter" target="_blank" rel="noopener">@vasanthdevelop</a> &nbsp;&middot;&nbsp;
133
- > Discord <a href="https://vas.cx/discord" target="_blank" rel="noopener">Vasanth Developer</a>
package/examples/index.js DELETED
@@ -1,11 +0,0 @@
1
- import itivrutaha from '../dist/itivrutaha.js'
2
-
3
- const logger = await itivrutaha.createNewLogger()
4
-
5
- logger.error('some error')
6
- logger.info('nice info')
7
- logger.note('a useful note')
8
- logger.okay(`it's okay`)
9
- logger.success('that is a success')
10
- logger.verbose('useful for developers')
11
- logger.warning('something is going wrong')
package/nodemon.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "quiet": true,
3
- "verbose": false,
4
- "ext": "ts",
5
- "exec": "node scripts/docs.js",
6
- "watch": [
7
- "./src"
8
- ]
9
- }
@@ -1,17 +0,0 @@
1
- /*
2
- * Run control for Prettier.
3
- * Created On 01 April 2021
4
- */
5
-
6
- module.exports = {
7
- semi: false,
8
- tabWidth: 4,
9
- useTabs: false,
10
- endOfLine: 'lf',
11
- singleQuote: true,
12
- trailingComma: 'all',
13
- bracketSpacing: true,
14
- arrowParens: 'avoid',
15
- parser: 'typescript',
16
- quoteProps: 'as-needed',
17
- }
package/scripts/docs.js DELETED
@@ -1,94 +0,0 @@
1
- /*
2
- * Reads source code and builds documentation.
3
- * Created On 19 April 2021
4
- */
5
-
6
- import chalk from 'chalk'
7
- import dirname from 'es-dirname'
8
- import fs from 'fs/promises'
9
- import mkdirp from 'mkdirp'
10
- import path from 'path'
11
-
12
- const dest = path.join(dirname(), '..', 'docs', 'Customization.md')
13
-
14
- const getHeaderFooter = async () => {
15
- const readme = await fs.readFile(path.join(dirname(), '..', 'README.md'), {
16
- encoding: 'utf-8',
17
- })
18
-
19
- const header = readme.split('<!-- header -->')[0].trim()
20
- const footer = readme.split('<!-- footer -->')[1].trim()
21
-
22
- return { header, footer }
23
- }
24
-
25
- const getCustomization = async () => {
26
- const indexFile = await fs.readFile(
27
- path.join(dirname(), '..', 'src', 'itivrutaha.ts'),
28
- {
29
- encoding: 'utf-8',
30
- },
31
- )
32
-
33
- return indexFile
34
- .split('const defaults: ConfigImpl = {')[1]
35
- .split('\n}')[0]
36
- .slice(1)
37
- }
38
-
39
- const getVariables = async () => {
40
- const renderer = await fs.readFile(
41
- path.join(dirname(), '..', 'src', 'class', 'renderer.ts'),
42
- { encoding: 'utf-8' },
43
- )
44
-
45
- let returnable = ''
46
-
47
- const lines = renderer
48
- .split('// <!-- docs -->')[1]
49
- .split('\n')
50
- .map(line => line.trim())
51
- .filter(line => line != '')
52
- .join('\n')
53
- .split('\n//')
54
-
55
- for (const line of lines) {
56
- const comment = line.split('\n')[0].replace('// ', '').trim()
57
- const code = line.split('\n')[1].slice(10).split("'")[0]
58
-
59
- returnable = `${returnable}| \`${code}\` | ${comment} |\n`
60
- }
61
-
62
- return returnable
63
- }
64
-
65
- const readme = await getHeaderFooter()
66
- const customization = await getCustomization()
67
- const variables = await getVariables()
68
-
69
- const contents = readme.header
70
- .concat('\n\n## šŸ›  Customization')
71
- .concat('\n\n```javascript')
72
- .concat(
73
- `
74
- import chalk from 'chalk'
75
- import itivrutaha from 'itivrutaha'
76
- `
77
- .split('\n')
78
- .map(line => line.trim())
79
- .join('\n'),
80
- )
81
- .concat('\n// create a new instance of the logger')
82
- .concat('\nconst logger = await itivrutaha.createNewLogger({\n')
83
- .concat(customization)
84
- .concat('\n})\n```')
85
- .concat('\n\n## āš”ļø Variables')
86
- .concat('\n\n| Variable | Description |')
87
- .concat('\n|-|-|\n')
88
- .concat(variables)
89
- .concat('\n\n')
90
- .concat(readme.footer)
91
-
92
- await mkdirp(path.dirname(dest))
93
- await fs.writeFile(dest, contents)
94
- console.log(`āœ… ${chalk.greenBright.bold('Built')} ${dest}`)
@@ -1,60 +0,0 @@
1
- /*
2
- * This class which holds all the log functions.
3
- * Created On 11 October 2019
4
- */
5
-
6
- import { ConfigImpl, configSchema, DataImpl } from '../config.js'
7
- import lifecycle from './lifecycle.js'
8
- import render from './wrapper.js'
9
-
10
- export class Logger {
11
- // store the config and data globally
12
- // relative to this class
13
- public config: ConfigImpl
14
- public data: DataImpl
15
-
16
- // constructor() executes when the class is initialized
17
- constructor(config: ConfigImpl, data: DataImpl) {
18
- const valid = configSchema.validate(config)
19
- if (valid.error)
20
- throw new Error(
21
- `itivrutaha was misconfigured: ${valid.error.message}`,
22
- )
23
-
24
- // make the config globally relative accessible
25
- this.config = valid.value
26
- this.data = data
27
-
28
- // log a message that the the application has
29
- // started/stopped as per user's request
30
- lifecycle(valid.value, data)
31
- }
32
-
33
- public success = (msg: string): void =>
34
- render({ msg, config: this.config, data: this.data })
35
- public note = (msg: string): void =>
36
- render({ msg, config: this.config, data: this.data })
37
- public info = (msg: string): void =>
38
- render({ msg, config: this.config, data: this.data })
39
- public okay = (msg: string): void =>
40
- render({ msg, config: this.config, data: this.data })
41
-
42
- public warning = (msg: string | Error): void =>
43
- render({ msg, config: this.config, data: this.data })
44
- public error = (msg: string | Error, exitCode?: number): void =>
45
- render({ msg, config: this.config, data: this.data, exitCode })
46
-
47
- // verbose() will only log the message
48
- // when a flag/command/option is found in the
49
- // command-line arguments
50
- public verbose = (msg: string): void =>
51
- render({
52
- msg,
53
- config: this.config,
54
- data: this.data,
55
- condition: () =>
56
- this.config.verboseIdentifier.some(argument =>
57
- process.argv.includes(argument),
58
- ),
59
- })
60
- }
@@ -1,79 +0,0 @@
1
- /*
2
- * Logs when application starts or stops.
3
- * Created On 15 April 2021
4
- */
5
-
6
- import ctl from 'clear-terminal-line'
7
- import { DateTime } from 'luxon'
8
- import cleanup from 'node-cleanup'
9
-
10
- import { ConfigImpl, DataImpl } from '../config'
11
- import { close } from './log.js'
12
- import render from './wrapper.js'
13
-
14
- const startup = (config: ConfigImpl, data: DataImpl): void => {
15
- render({
16
- data,
17
- config,
18
- msg: `${config.appName} startup`,
19
- type: 'note',
20
- condition: () => config.bootLog,
21
- })
22
-
23
- render({
24
- data,
25
- config,
26
- msg: `Started on ${DateTime.local().toFormat(
27
- 'hh:mm:ss a, LLL dd yyyy',
28
- )}`,
29
- type: 'info',
30
- condition: () => config.bootLog,
31
- })
32
- }
33
-
34
- const shutdown = (config: ConfigImpl, data: DataImpl, signal: string): void => {
35
- const now = DateTime.local().diff(data.startedOn, [
36
- 'days',
37
- 'hours',
38
- 'minutes',
39
- 'seconds',
40
- 'milliseconds',
41
- ])
42
-
43
- const time = []
44
- now.days && time.push(`${Math.round(now.days)} days`)
45
- now.hours && time.push(`${Math.round(now.hours)} hours`)
46
- now.minutes && time.push(`${Math.round(now.minutes)} minutes`)
47
- now.seconds && time.push(`${Math.round(now.seconds)} seconds`)
48
- now.milliseconds && time.push(`${Math.round(now.milliseconds)} ms`)
49
-
50
- if (signal == 'SIGINT' && config.clearOnSIGINT) {
51
- ctl()
52
- process.stdout.write('\r')
53
- }
54
-
55
- render({
56
- data,
57
- config,
58
- msg: `Bye šŸ‘‹ ran for ${time.slice(-3).join(', ')}`,
59
- type: 'info',
60
- condition: () => config.shutdownLog,
61
- })
62
-
63
- render({
64
- data,
65
- config,
66
- msg: `${config.appName} shutdown`,
67
- type: 'note',
68
- condition: () => config.shutdownLog,
69
- })
70
-
71
- close(true, data)
72
- }
73
-
74
- export default (config: ConfigImpl, data: DataImpl): void => {
75
- startup(config, data)
76
- cleanup((exitCode, signal) => {
77
- shutdown(config, data, signal)
78
- })
79
- }
package/src/class/log.ts DELETED
@@ -1,78 +0,0 @@
1
- /*
2
- * Handles writing log files.
3
- * Created On 15 April 2021
4
- */
5
-
6
- import paths from 'env-paths'
7
- import fs from 'fs/promises'
8
- import { DateTime } from 'luxon'
9
- import mkdirp from 'mkdirp'
10
- import cleanup from 'node-cleanup'
11
- import path from 'path'
12
- import strip from 'strip-ansi'
13
-
14
- import { ConfigImpl, DataImpl } from '../config'
15
-
16
- export const close = async (close: boolean, data: DataImpl): Promise<void> => {
17
- if (close && (data.error || data.output)) {
18
- await data.output.close()
19
- await data.error.close()
20
- }
21
- }
22
-
23
- export const open = async (config: ConfigImpl): Promise<DataImpl> => {
24
- // variable to store data
25
- const data: DataImpl = {
26
- startedOn: DateTime.local(),
27
- }
28
-
29
- if (config.logs.enable == true && !config.logs.dir) {
30
- const { log } = paths(config.appName, {
31
- suffix: '',
32
- })
33
-
34
- config.logs.dir = log
35
- }
36
- if (config.logs.enable) {
37
- // make sure that the folder exists
38
- await mkdirp(config.logs.dir)
39
-
40
- // open log files
41
- data.output = await fs.open(
42
- path.join(config.logs.dir, config.logs.output),
43
- 'a',
44
- 0o666,
45
- )
46
-
47
- data.error = await fs.open(
48
- path.join(config.logs.dir, config.logs.error),
49
- 'a',
50
- 0o666,
51
- )
52
- }
53
-
54
- // attach the closing hook
55
- cleanup(() => {
56
- close(!config.shutdownLog, data)
57
- })
58
-
59
- return data
60
- }
61
-
62
- export default async (
63
- log: string,
64
- type: string,
65
- config: ConfigImpl,
66
- data: DataImpl,
67
- ): Promise<void> => {
68
- if (config.logs.enable == false) return
69
-
70
- // whether to write in error or output file
71
- const stream = ['error', 'warning'].includes(type) ? 'error' : 'output'
72
-
73
- // strip ansi terminal styling codes
74
- log = strip(log) + '\n'
75
-
76
- // write it!
77
- await data[stream].appendFile(log)
78
- }
@@ -1,49 +0,0 @@
1
- /*
2
- * This file will replace all the placeholders with real values.
3
- * Created On 12 October 2019
4
- */
5
-
6
- import ne from 'node-emoji'
7
- import path from 'path'
8
-
9
- import { ConfigImpl } from '../config.js'
10
- import emoji from './variables/emoji.js'
11
- import time from './variables/time.js'
12
- import type from './variables/type.js'
13
-
14
- export default (typeStr: string, msg: string, config: ConfigImpl): string =>
15
- config.theme.string
16
-
17
- // <!-- docs -->
18
- // The time of the log message. A [Luxon](https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens) format string can be given as `theme.timeFormat` to change the formatting.
19
- .replace(':time', time(config))
20
-
21
- // Emoji according to the message type.
22
- .replace(':emoji', emoji(typeStr))
23
-
24
- // Log message in terminal's default color.
25
- .replace(':message', ne.emojify(msg))
26
-
27
- // Full path to Node.js executable.
28
- .replace(':node_path', process.argv[0])
29
-
30
- // Message type (ie. info, warning, error, etc).
31
- .replace(':type', type(typeStr, config))
32
-
33
- // Full path of the Node.js entry JavaScript file.
34
- .replace(':script_path', process.argv[1])
35
-
36
- // Version of Node.js running.
37
- .replace(':node_version', process.version)
38
-
39
- // Version of V8 engine running along with Node.js.
40
- .replace(':v8_version', process.versions.v8)
41
-
42
- // Filename of the Node.js entryfile.
43
- .replace(':filename', path.basename(process.argv[1]))
44
-
45
- // Version of OpenSSL running along with Node.js.
46
- .replace(':openssl_version', process.versions.openssl)
47
-
48
- // Version of Electron.js running. Returns `undefined` if not Electron.
49
- .replace(':electron_version', process.versions.electron)
@@ -1,19 +0,0 @@
1
- /*
2
- * Renders ":emoji" variable in log messages.
3
- * Created On 15 April 2021
4
- */
5
-
6
- import emoji from 'node-emoji'
7
-
8
- const emojis = {
9
- okay: 'thumbsup',
10
- info: 'loudspeaker',
11
- error: 'x',
12
- note: 'memo',
13
- verbose: 'telescope',
14
- success: 'white_check_mark',
15
- warning: 'construction',
16
- }
17
-
18
- export default (type: string): string =>
19
- emoji.emojify(`:${emojis[type]}:`).trim()
@@ -1,14 +0,0 @@
1
- /*
2
- * This file will render the ":time" variable.
3
- * Created On 12 October 2019
4
- */
5
-
6
- import chalk from 'chalk'
7
- import { DateTime } from 'luxon'
8
-
9
- import { ConfigImpl } from '../../config.js'
10
-
11
- export default (config: ConfigImpl): string =>
12
- config.theme.colored
13
- ? chalk.gray.dim(DateTime.local().toFormat(config.theme.timeFormat))
14
- : DateTime.local().toFormat(config.theme.timeFormat)
@@ -1,50 +0,0 @@
1
- /*
2
- * This file will render the ":type" variable in the theme.
3
- * Created On 12 October 2019
4
- */
5
-
6
- import chalk from 'chalk'
7
-
8
- import { ConfigImpl } from '../../config.js'
9
-
10
- // bold() will make the text bold
11
- const bold = (type: string, config: ConfigImpl): string =>
12
- config.theme.boldType ? chalk.bold(type) : type
13
-
14
- // this function will call the rest of the styling
15
- // functions will make a function chain like that
16
- const colorize = (type: string, config: ConfigImpl): string => {
17
- if (!config.theme.colored) return bold(type, config)
18
-
19
- const colors = {
20
- okay: chalk.gray,
21
- info: chalk.blueBright,
22
- error: chalk.redBright,
23
- note: chalk.magentaBright,
24
- verbose: chalk.cyanBright,
25
- success: chalk.greenBright,
26
- warning: chalk.yellowBright,
27
- }
28
-
29
- return bold(colors[type](type), config)
30
- }
31
-
32
- // casing() will set the character casing
33
- const casing = (type: string, config: ConfigImpl): string => {
34
- const toTitleCase = (str): string =>
35
- str.replace(
36
- /\w\S*/g,
37
- txt => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(),
38
- )
39
-
40
- const func = {
41
- 0: (str: string) => str.toUpperCase(),
42
- 1: (str: string) => str.toLowerCase(),
43
- 2: (str: string) => toTitleCase(str),
44
- }
45
-
46
- return colorize(func[config.theme.typeCase](type), config)
47
- }
48
-
49
- export default (type: string, config: ConfigImpl): string =>
50
- casing(type, config)
@@ -1,52 +0,0 @@
1
- /*
2
- * A wrapper function that handles all specifics
3
- * before passing data to the render function.
4
- * Created On 14 April 2021
5
- */
6
-
7
- import { ConfigImpl, DataImpl } from '../config.js'
8
- import writeLog from './log.js'
9
- import renderer from './renderer.js'
10
-
11
- const getType = (): string =>
12
- new Error().stack.split('\n')[3].trim().slice(10).split(' ')[0]
13
-
14
- export default ({
15
- msg,
16
- type,
17
- data,
18
- config,
19
- exitCode,
20
- condition,
21
- }: {
22
- type?: string
23
- data: DataImpl
24
- exitCode?: number
25
- config: ConfigImpl
26
- msg: string | Error
27
- condition?: (config: ConfigImpl) => boolean
28
- }): void => {
29
- // check if there's a condition
30
- const showOutput = condition ? condition(config) : true
31
-
32
- // set the type, incase it isn't already
33
- if (!type) type = getType()
34
-
35
- // handle if Error or message string
36
- if (typeof msg == 'object') msg = msg.message
37
-
38
- // render the log message
39
- const log = renderer(type, msg, config)
40
- writeLog(log, type, config, data)
41
- if (!showOutput) return
42
- if (
43
- config.quietIdentifier.some(argument =>
44
- process.argv.includes(argument),
45
- ) == false
46
- ) {
47
- console.log(log)
48
- }
49
-
50
- // handle the exitCode
51
- if (exitCode) process.exit(exitCode)
52
- }
package/src/config.ts DELETED
@@ -1,76 +0,0 @@
1
- /*
2
- * This file will contain code related to loading and storing configuration.
3
- * Created On 11 October 2019
4
- */
5
-
6
- import { FileHandle } from 'fs/promises'
7
- import Joi from 'joi'
8
- import { DateTime } from 'luxon'
9
-
10
- // typeCase enumerator will hold the
11
- // int values for type string case
12
- export enum typeCase {
13
- 'upper',
14
- 'lower',
15
- 'title',
16
- }
17
-
18
- // The skeleton which has all possible
19
- // settings passable to the Logger
20
- export interface ConfigImpl {
21
- appName: string
22
- bootLog: boolean
23
- shutdownLog: boolean
24
- clearOnSIGINT: boolean
25
- quietIdentifier: Array<string>
26
- verboseIdentifier: Array<string>
27
- context?: {
28
- name: string
29
- color: (str: string) => string
30
- }
31
- theme?: {
32
- string: string
33
- colored: boolean
34
- boldType: boolean
35
- typeCase: typeCase
36
- timeFormat: string
37
- }
38
- logs: {
39
- dir: string
40
- error: string
41
- output: string
42
- enable: boolean
43
- }
44
- }
45
-
46
- export const configSchema = Joi.object({
47
- appName: Joi.string(),
48
- bootLog: Joi.bool().required(),
49
- shutdownLog: Joi.bool().required(),
50
- clearOnSIGINT: Joi.bool().required(),
51
- quietIdentifier: Joi.array().items(Joi.string()),
52
- verboseIdentifier: Joi.array().items(Joi.string()),
53
- context: Joi.object({
54
- color: Joi.any().required(),
55
- name: Joi.string().allow(null).required(),
56
- }),
57
- theme: Joi.object({
58
- string: Joi.string().required(),
59
- colored: Joi.bool(),
60
- boldType: Joi.bool(),
61
- typeCase: Joi.number(),
62
- timeFormat: Joi.string(),
63
- }),
64
- logs: Joi.object({
65
- dir: Joi.string().allow(null).required(),
66
- output: Joi.string().required(),
67
- error: Joi.string().required(),
68
- enable: Joi.bool().required(),
69
- }),
70
- })
71
-
72
- export interface DataImpl {
73
- output?: FileHandle
74
- error?: FileHandle
75
- startedOn: DateTime
76
- }
package/src/itivrutaha.ts DELETED
@@ -1,140 +0,0 @@
1
- /*
2
- * Entryfile for itivrutaha logging module.
3
- * Created On 10 October 2019
4
- */
5
-
6
- import chalk from 'chalk'
7
- import merge from 'deepmerge'
8
- import del from 'del'
9
- import { DateTime } from 'luxon'
10
- import { readPackageUpSync } from 'read-pkg-up'
11
-
12
- import { Logger } from './class/index.js'
13
- import { open } from './class/log.js'
14
- import { ConfigImpl, typeCase } from './config.js'
15
-
16
- // Holds the default configuration which acts like a
17
- // replacement when no value is provided for a
18
- // particular configuration key
19
- const defaults: ConfigImpl = {
20
- // The name of your app, if not provided
21
- // the value will be determined by reading
22
- // package.json of the above project.
23
- appName: null,
24
-
25
- // Whether to log when the logger is initialized.
26
- bootLog: true,
27
-
28
- // Whether to log when the Node.js process exits.
29
- // Logs when terminating gracefully, due to an error
30
- // or when POSIX signals are received.
31
- shutdownLog: true,
32
-
33
- // remove the "^CāŽ" after terminating the process
34
- // when Ctrl+C is pressed
35
- clearOnSIGINT: true,
36
-
37
- // Command-line arguments that suppress the output
38
- // to the console if found.
39
- quietIdentifier: ['--quiet', '-q'],
40
-
41
- // Command-line arguments that render verbose message
42
- // type to the console if found.
43
- verboseIdentifier: ['--verbose', '-v'],
44
-
45
- // Configuration for this particular logger.
46
- // Useful when application has multiple loggers.
47
- context: {
48
- // Name of the context, example "app", "api",
49
- // "bot", "server"...
50
- name: null,
51
-
52
- // Chalk color function for this context.
53
- color: chalk.blueBright,
54
- },
55
-
56
- // Configuration options related to rendering the
57
- // log messages to the console.
58
- theme: {
59
- // The theme string, that determines which variables
60
- // are to be rendered.
61
- string: `:time ${chalk.gray.dim('•')} :emoji :type :message`,
62
-
63
- // Whether to log colored output
64
- // or plain.
65
- colored: true,
66
-
67
- // Whether to render message type (":type" variable)
68
- // in bold.
69
- boldType: true,
70
-
71
- // The character casing to render message type or
72
- // the (":type" variable).
73
- typeCase: typeCase.lower,
74
-
75
- // Luxon time formatting used to render the
76
- // ":time" variable. See šŸ‘‡ for formatting guide
77
- // https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens
78
- timeFormat: 'HH:mm:ss dd-LL-yyyy',
79
- },
80
-
81
- logs: {
82
- // Whether to enable file logging or not.
83
- enable: false,
84
-
85
- // The directory where log files are saved.
86
- dir: null,
87
-
88
- // Filename for writing output (stdout)
89
- // logs.
90
- output: `output-${DateTime.local().toFormat('dd-LL-yyyy')}.log`,
91
-
92
- // Filename for writing error (stderr)
93
- // logs.
94
- error: `error-${DateTime.local().toFormat('dd-LL-yyyy')}.log`,
95
- },
96
- }
97
-
98
- // createNewLogger() will create a new instance of the logger class
99
- const createNewLogger = async (
100
- config: ConfigImpl = defaults,
101
- ): Promise<Logger> => {
102
- // if custom properties were given merge those together
103
- // with defaults so we have all properties defined
104
- config = merge(defaults, config)
105
-
106
- // fill out the fields which are specific to this
107
- // particular instance of Logger
108
- if (config.appName == null)
109
- config.appName = readPackageUpSync().packageJson.name
110
- if (config.context.name)
111
- config.theme.string = `:time ${chalk.gray.dim(
112
- '•',
113
- )} ${config.context.color(config.context.name)} :emoji :type :message`
114
-
115
- // initialize file logging according to the configuration
116
- const data = await open(config)
117
-
118
- // return a new LoggerClass instance
119
- return new Logger(config, data)
120
- }
121
-
122
- const clearLogs = async (logger: Logger): Promise<string[]> =>
123
- await del(logger.config.logs.dir, { force: true })
124
-
125
- // Export the above two functions
126
- export default {
127
- /**
128
- * Creates a new instance of a logger.
129
- * @param config {ConfigImpl}
130
- * @returns Logger
131
- */
132
- createNewLogger,
133
-
134
- /**
135
- * Deletes the log directory for a given logger.
136
- * @param logger {Logger}
137
- * @returns string[]
138
- */
139
- clearLogs,
140
- }
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "compileOnSave": true,
3
- "compilerOptions": {
4
- "alwaysStrict": true,
5
- "charset": "UTF-8",
6
- "declaration": true,
7
- "esModuleInterop": true,
8
- "moduleResolution": "node",
9
- "module": "ESNext",
10
- "newLine": "LF",
11
- "preserveConstEnums": true,
12
- "rootDir": "src/",
13
- "outDir": "dist/",
14
- "target": "ES2015",
15
- "incremental": true
16
- }
17
- }