Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.0: Merging dev to main. #2

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Publish to NPM

on:
push:
tags:
- 'v*'
branches:
- main # For test runs
pull_request:
branches:
- main # For PR validation

jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

# - name: Run tests
# run: npm test

publish:
needs: verify
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
48 changes: 48 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# TypeScript build output
dist/
build/
*.tsbuildinfo

# Test coverage
coverage/

# IDE and editor files
.idea/
.vscode/
*.swp
*.swo
.DS_Store
Thumbs.db

# Environment variables
.env
.env.local
.env.*.local

# Logs
logs/
*.log

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# Debug log from npm
npm-debug.log*
78 changes: 77 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
# dlog
# LELOG - lelog

A dual-environment logger that automatically switches between server and client logging.

- Supports Typescript.

## Installation

```bash
npm i lelog
or
npm install lelog
```

## Usage

**Usage 1** (Only import and use with default class name (lelog))

```typescript
// Use directly
import lelog from 'lelog';

lelog.info('Hello World');

lelog.info('Hello World', true); // true bool adds timestamp output to log.
```

**Usage 2** (Import and init with custom class name (can be direct class name or string))

```typescript
// custom instance with different class name
import { lelog } from 'lelog';

const lelog = lelog('MyCustomClass');
lelog.info('Custom logger message');

lelog.info('Custom logger message', true); // true bool adds timestamp output to log.
```

## lelog types:

- Standard logging with multi-color

`lelog.info('Standart info log 🚀🚀🚀');`

`lelog.warn('Standart warning log');`

`lelog.error('Standart error log');`
- Custom colored message usages:

`lelog.logColored('Custom colored log message', { message: '#8e44ad', className: '#F5eead' });`
- Background colored log message usage:

`lelog.logWithBackground('Log message with background', '#2ecc71');`
- Gradient message usage:

`lelog.logGradient('Gradient colored log message 01234567890123456789012345678901234567890');`
- Boxed message usage:

`lelog.logBox('Info log in a box', '#2ecc71');`
- Log group usage:

`lelog.logGroup('Log group message', { action: 'click', element: 'button', });`

## Showcase & Usage examples:

(browser console)

![image](https://github.com/user-attachments/assets/70745c1c-60c5-456b-8dbf-e2b18750b76a)

(nodejs - middleware.ts - terminal)

![image](https://github.com/user-attachments/assets/39438bed-b653-46b6-8ba2-1f6277b3476b)

(with time bool true (that bool is optional if not entered "false" will be default))

![image]()
10 changes: 10 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { initlelog } from './src/factory';

// Create a default instance with a default class name
const lelog = initlelog('leLog');

// Export the pre-initialized instance as default
export default lelog;

// Also export the factory function
export { initlelog };
48 changes: 48 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "lelog",
"version": "1.0.0",
"description": "Dual-environment logger for both client and server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist",
"README.md"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsc",
"prepare": "npm run build"
},
"author": "gbpii",
"license": "ISC",
"repository": {
"type": "git",
"url": "git+https://github.com/unovatria/lelog.git"
},
"keywords": [
"NPM",
"Debug",
"Logger",
"Log",
"logger",
"typescript",
"nodejs",
"browser"
],
"bugs": {
"url": "https://github.com/unovatria/lelog/issues"
},
"homepage": "https://github.com/unovatria/lelog#readme",
"devDependencies": {
"@types/node": "^22.10.2",
"typescript": "^5.7.2"
}
}
46 changes: 46 additions & 0 deletions src/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { LogLevel } from "./types-and-schemes";

export abstract class BaseLogger {

protected className: string;

constructor(className: string) {
this.className = className;
}

abstract log(level: LogLevel, message: string, time?: boolean, error?: unknown): void;
abstract logColored(message: string, customColors: unknown, time?: boolean): void;
abstract logWithBackground(message: string, bgColor: string, time?: boolean): void;
abstract logGradient(message: string, time?: boolean): void;
abstract logBox(message: string, boxColor: string, time?: boolean): void;
abstract logGroup(title: string, details: Record<string, unknown>, time?: boolean): void;

public info(message: string, time?: boolean) {
this.log('info', message, time);
return;
}

public warn(message: string, time?: boolean) {
this.log('warn', message, time);
return;
}

public error(message: string, time?: boolean, error?: unknown) {
this.log('error', message, time, error);
return;
}

public async withTry<T>(
operation: () => Promise<T> | T,
time = true,
errorMessage = 'Operation failed'
): Promise<T | undefined> {
try {
const result = await operation();
return result;
} catch (error) {
this.error(errorMessage, time, error);
return undefined;
}
}
}
Loading
Loading