Skip to content

Conversation

@jkebinger
Copy link
Contributor

Summary

This PR restores log level functionality similar to the predecessor project (prefab-cloud-js) with a simplified, non-hierarchical approach suitable for client-side evaluation.

Changes

New Features

1. LogLevel Enum

  • Public LogLevel enum with values: TRACE, DEBUG, INFO, WARN, ERROR, FATAL
  • Exported for use in application code

2. getLogLevel(loggerName) Method

  • Returns a LogLevel enum value
  • Looks up configured logger key (default: "log-levels.default")
  • Returns LogLevel.DEBUG as default if not configured
  • Note: loggerName parameter currently unused (all loggers share same level)

3. Logger Convenience Methods

  • New reforge.logger.* API with methods: trace(), debug(), info(), warn(), error(), fatal()
  • Automatically checks configured log level before logging
  • Maps to appropriate console methods
  • Simple, clean API: reforge.logger.info("message")

4. Helper Functions

  • shouldLogAtLevel(configuredLevel, desiredLevel) - Compare LogLevel enum values (recommended)
  • getLogLevelSeverity(level) - Get numeric severity for manual comparison

5. Configuration

  • New optional loggerKey init parameter (default: "log-levels.default")
  • All loggers share the same global log level

Breaking Changes

shouldLog() No Longer Traverses Hierarchy

  • Old behavior: Traversed logger name hierarchy (e.g., log-level.my.applog-level.mylog-level)
  • New behavior: Exact key match only (log-level.{loggerName})
  • Reason: Client-side evaluation with single context means hierarchy traversal isn't meaningful

This simplification aligns with the architectural constraint that the server evaluates configs once per request with a single context.

Test Coverage

  • Added 18 new test cases
  • All 73 tests passing
  • Coverage includes:
    • LogLevel enum values
    • getLogLevel() with various configurations
    • Logger methods at all levels
    • Helper functions (shouldLogAtLevel, getLogLevelSeverity)
    • shouldLog() exact match behavior

Documentation

  • Updated README with comprehensive sections:
    • getLogLevel() usage and configuration
    • logger.* methods with examples
    • LogLevel comparison helpers
    • Console method mapping
    • Updated shouldLog() docs to reflect no-hierarchy behavior

Example Usage

import { reforge, LogLevel, Context } from "@reforge-com/javascript";

await reforge.init({
  sdkKey: "your-key",
  context: new Context({ user: { id: "123" } }),
  loggerKey: "log-levels.default", // optional
});

// Configure log level
reforge.hydrate({ "log-levels.default": "INFO" });

// Use the logger
reforge.logger.debug("Debug message");  // Not logged (below INFO)
reforge.logger.info("Info message");    // ✓ Logged
reforge.logger.warn("Warning");         // ✓ Logged
reforge.logger.error("Error");          // ✓ Logged

// Or check level programmatically
const level = reforge.getLogLevel("my.logger");
if (shouldLogAtLevel(level, LogLevel.DEBUG)) {
  console.debug("Debug details");
}

Migration Notes

If you were using shouldLog() with hierarchical logger names, you'll need to:

  • Update to use exact key matches for log-level.{loggerName} configs
  • OR switch to using reforge.logger.* methods with the global log level
  • OR use getLogLevel() + shouldLogAtLevel() for programmatic checks

🤖 Generated with Claude Code

jkebinger and others added 3 commits November 4, 2025 14:10
- Add LogLevel enum (TRACE, DEBUG, INFO, WARN, ERROR, FATAL)
- Add getLogLevel(loggerName) method that returns LogLevel enum
- Add configurable loggerKey option (default: "log-levels.default")
- Add reforge.logger.* convenience methods (trace, debug, info, warn, error, fatal)
- Add shouldLogAtLevel() helper for comparing LogLevel values
- Add getLogLevelSeverity() helper for numeric severity comparison
- Remove hierarchy traversal from shouldLog() - now uses exact key match only
- Add comprehensive test coverage (73 tests passing)
- Update README with full documentation and examples

The logger methods automatically check the configured log level and only
output to console when appropriate. All loggers share the same global
log level from the configured key.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add .idea/, .claude/, and .yarn/ to .gitignore to prevent tracking
local IDE configurations and tool directories.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Use ${NPM_AUTH_TOKEN-} syntax to allow empty default when env var is not set.
This enables local yarn install without the token while still working in CI/CD.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jkebinger jkebinger force-pushed the restore-log-level-functionality branch from a02884d to 72f8ceb Compare November 4, 2025 19:19
jkebinger and others added 4 commits November 4, 2025 14:21
- Simplify arrow functions to remove unnecessary block statements
- Add default case to switch statement in ReforgeLogger
- Fix no-use-before-define errors with eslint-disable comments
- Prefix unused parameter with underscore in getLogLevel
- Add eslint-disable comments for console usage in tests
- Add max-classes-per-file disable for ReforgeLogger and Reforge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Update test expectations to match actual ReforgeLogLevel enum values:
- WARN: 4 (not 5)
- ERROR: 5 (not 6)
- FATAL: 6 (not 9)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@jdwyah jdwyah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@jkebinger jkebinger merged commit 93c38af into main Nov 4, 2025
1 check passed
@jkebinger jkebinger deleted the restore-log-level-functionality branch November 4, 2025 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants