Compare commits

...

5 commits

Author SHA1 Message Date
b9df7eec73 1.0.2 2023-08-15 09:54:46 +01:00
a9cfbfa8ae 1.0.1 2023-08-15 09:46:33 +01:00
fd15c3eadb
Update README.md 2023-08-15 09:44:10 +01:00
0bc6ba72fe
Create README.md 2023-08-15 09:42:58 +01:00
1e305535e7
Create workflow 2023-08-15 09:25:14 +01:00
4 changed files with 67 additions and 4 deletions

33
.github/workflows/node.js.yml vendored Normal file
View file

@ -0,0 +1,33 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Node.js CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
# Don't run updateCheck for now
#- run: npm run dev:updateCheck
- run: npm run build
#- run: npm test

29
README.md Normal file
View file

@ -0,0 +1,29 @@
# hsconsole   [![CodeFactor](https://www.codefactor.io/repository/github/tgpholly/hsconsole/badge)](https://www.codefactor.io/repository/github/tgpholly/hsconsole)   [![Node.js CI](https://github.com/tgpholly/hsconsole/actions/workflows/node.js.yml/badge.svg?branch=master)](https://github.com/tgpholly/hsconsole/actions/workflows/node.js.yml)   [![npm](https://img.shields.io/npm/v/hsconsole)](https://www.npmjs.com/package/hsconsole)
I've been using this logger code since I started the move of all my applications to TypeScript with some modifications. It's based on an even earlier version initially started in [Revolution](https://github.com/tgpholly/Revolution). Since it's essentially the same every time I decided to make it an NPM package so I can reuse it.
## What does this do
hsconsole logs to the console in a clean, formatted and readable way while also writing to log files on disk. All logs are kept until you decide to delete them.
## Usage
Import the `Console` class from hsconsole
```js
const { Console } = require("hsconsole");
```
```ts
import { Console } from "hsconsole";
```
and use it by calling either `printInfo`, `printWarn` or `printError`.
You can also specify a custom header to prepend to the start of the log file using `customHeader` as follows:
```ts
Console.customHeader(`xyz started at ${new Date()}`);
```
This must be called this before anything is logged to the console!
## Cleaning up
It is **important** that you tell hsconsole to clean up before your application closes (i.e in the event of a CTRL+C) so it can be ensured that all log text is flushed to disk and to allow hsconsole to rename the latest log to the date your application was started.
You can do this by calling `cleanup` in, for example, a **SIGINT** event handler:
```ts
process.on("SIGINT", signal => {
Console.cleanup();
});
```
The above should work on both *nix and Windows systems.

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "hsconsole",
"version": "1.0.0",
"version": "1.0.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "hsconsole",
"version": "1.0.0",
"version": "1.0.2",
"license": "MIT",
"dependencies": {
"dyetty": "^1.0.1"

View file

@ -1,8 +1,9 @@
{
"name": "hsconsole",
"version": "1.0.0",
"version": "1.0.2",
"description": "",
"main": "index.js",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"updateCheck": "check-outdated",
"build": "tsc --build",