Skip to content
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
12 changes: 0 additions & 12 deletions .babelrc

This file was deleted.

16 changes: 16 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"permissions": {
"allow": [
"Bash(ls:*)",
"Bash(npm run example:*)",
"Bash(npm test)",
"Bash(npm run build:*)",
"Bash(npm run lint:*)",
"Bash(rm:*)",
"Bash(pnpm:*)",
"Bash(pnpm test:*)",
"Bash(node:*)"
],
"deny": []
}
}
59 changes: 0 additions & 59 deletions .eslintrc.js

This file was deleted.

46 changes: 46 additions & 0 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish Pre-release

on:
pull_request:
branches: [ master ]
types: [opened, synchronize, reopened]

jobs:
build-and-publish:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- uses: pnpm/action-setup@v3
with:
version: latest
run_install: true
- run: pnpm typecheck
- run: pnpm lint
- run: pnpm build
- name: Run tests
run: pnpm test

- name: Get PR commit count
id: pr_commits
run: |
count=$(gh pr view ${{ github.event.pull_request.number }} --json commits --jq '.commits | length')
echo "commit_count=$count" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ github.token }}

- name: Update version for pre-release
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
PRERELEASE_VERSION="${PACKAGE_VERSION}-pr${{ github.event.number }}.${{ steps.pr_commits.outputs.commit_count }}"
npm version $PRERELEASE_VERSION --no-git-tag-version
echo "Publishing version: $PRERELEASE_VERSION"

- name: Publish pre-release to npm
run: pnpm publish --tag pr --no-git-checks --no-otp
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
27 changes: 27 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish to npm

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- uses: pnpm/action-setup@v3
with:
version: latest
run_install: true
- run: pnpm typecheck
- run: pnpm lint
- run: pnpm build
- name: Run tests
run: pnpm test
- run: pnpm publish --no-git-checks --no-otp
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, 22.x, 24.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: pnpm/action-setup@v3
with:
version: latest
run_install: true
- run: pnpm typecheck
- run: pnpm lint
- run: pnpm build
- name: Run tests
run: pnpm test
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

88 changes: 88 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Commands

### Build and Development

```bash
# Install dependencies
yarn install

# Build the project
yarn build

# Run the example
yarn example

# Start development mode
yarn start
```

### Testing and Quality Assurance

```bash
# Run tests (includes linting and example)
yarn test

# Run only tests with verbose output
yarn ava --verbose

# Update test snapshots
yarn update-snapshots

# Run linting
yarn lint

# Check for outdated dependencies
yarn outdated
```

### Publishing

```bash
# Prepare for publishing (runs build)
yarn prepublish

# Publish using np tool
yarn np
```

## Architecture

The `logging` package is a lightweight console logging library designed for Node.js with basic browser support.

### Core Components

1. **Main Logger Implementation (`src/logging.js`):**
- Creates a logger with different log levels: debug, info, warn, error, fatal, trace
- Uses chalk for colorized output
- Uses nicely-format for formatting complex objects
- Integrates with the debug module for debug-level logs

2. **Browser Implementation (`src/browser.js`):**
- Simplified version for browser environments
- Basic implementation to avoid breaking universal builds
- Does not include colored output or log level formatting

3. **TypeScript Definitions (`index.d.ts`):**
- Provides type definitions for TypeScript users
- Defines the Logger interface and its functions

### Usage Pattern

The package follows a factory pattern where `createLogger` is called with a module name to generate a logger instance with various log level methods:

```javascript
import createLogger from 'logging';
const logger = createLogger('ModuleName');
logger.info('message', data);
```

### Environment Configuration

- Debug logs are only visible when the DEBUG environment variable is set (e.g., DEBUG=ModuleName or DEBUG=*)
- Node.js version 4+ is supported
- Uses Babel for transpilation
- Testing is done with AVA
28 changes: 28 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 4,
"lineWidth": 100
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"trailingComma": "es5",
"semicolons": "always"
}
},
"files": {
"ignore": ["lib/**/*", ".claude/*"]
}
}
6 changes: 3 additions & 3 deletions examples/simple.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Yarn run example
import logging from '../src';
// npm run example
import logging from '../src/index.js';

const log = logging('Feature');

Expand All @@ -19,6 +19,6 @@ object.circularReference = object;
object[Symbol('foo')] = 'foo';
object.map = new Map();
object.map.set('prop', 'value');
object.array = [ 1, Number.NaN, Number.POSITIVE_INFINITY ];
object.array = [1, Number.NaN, Number.POSITIVE_INFINITY];

log.info(object);
24 changes: 24 additions & 0 deletions examples/simple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// npm run example
import logging from '../src/index.js';

const log = logging('Feature');

const details = { blah: true };
const error = new Error('This error is part of the example');
const context = { userid: 1 };
const etc = false;

log.debug('set DEBUG=Feature or DEBUG=* to see this one');
log.info('Interesting');
log.warn('Hmmm...', 123, false, { details });
log.error('Not good.', 'Not good at all.', { err: error }, { context }, { etc });
log.info('This\nwill\nspan\nmultiple\nlines.');

const object: Record<string, unknown> = { property: {} };
object.circularReference = object;
object[Symbol('foo') as unknown as string] = 'foo';
object.map = new Map();
(object.map as Map<string, string>).set('prop', 'value');
object.array = [1, Number.NaN, Number.POSITIVE_INFINITY];

log.info(object);
22 changes: 0 additions & 22 deletions index.d.ts

This file was deleted.

3 changes: 3 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tools]
node = "22"
pnpm = "latest"
Loading