Skip to content

Commit 7886fcf

Browse files
committed
improve recipes
1 parent fdac92e commit 7886fcf

24 files changed

+316
-498
lines changed

docs/recipes/logging.md

Lines changed: 30 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,15 @@
1818
}
1919
-->
2020

21-
# Logging in Lucee
21+
# Logging
2222

23-
Lucee's logging system is a powerful and flexible framework designed to provide insights into your application’s behavior.
23+
Logging helps you monitor errors, track events, and troubleshoot your applications. Lucee's logging system is built on Log4j2, giving you flexible control over what gets logged, where it goes, and how it's formatted.
2424

25-
By configuring logs, you can monitor errors, track events, and troubleshoot efficiently.
25+
You can configure log levels to control verbosity, choose appenders to direct output (console, files, databases, or custom destinations like Kafka), and select layouts to format the output.
2626

27-
## Why Logging?
27+
## Log Levels
2828

29-
Logging is an essential practice for maintaining reliable and performant applications. It allows you to:
30-
31-
- Monitor runtime behavior and identify issues.
32-
- Gain insights into application usage and performance.
33-
- Maintain an audit trail of events and actions.
34-
35-
Lucee supports various log types (or levels), enabling you to control the verbosity and focus of your logs.
36-
37-
Additionally, you can configure logging destinations and formats to integrate seamlessly with your infrastructure.
38-
39-
## How to Use Log Levels?
40-
41-
Log levels (or types) categorize log entries based on their importance or severity. Lucee supports the following log levels in decreasing order of severity:
29+
In decreasing order of severity:
4230

4331
- **fatal**: Severe errors causing premature termination.
4432
- **error**: Runtime errors or unexpected conditions that require attention.
@@ -47,17 +35,13 @@ Log levels (or types) categorize log entries based on their importance or severi
4735
- **debug**: Detailed information helpful for debugging issues.
4836
- **trace**: The most detailed information for fine-grained troubleshooting.
4937

50-
### Configuring Log Level Thresholds
38+
### Log Level Thresholds
5139

52-
You can configure the minimum log level (threshold) for each logger in the **Lucee Administrator** or directly in the configuration file (`.CFConfig.json`).
40+
Configure minimum log level per logger in **Lucee Administrator** or `.CFConfig.json`. Setting threshold to `warn` records only warnings, errors, and fatal - ignoring `info`, `debug`, and `trace`.
5341

54-
For instance, setting a threshold of `warn` means only warnings, errors, and fatal logs are recorded, ignoring `info`, `debug`, and `trace` logs.
42+
### Redirecting Logs to Console
5543

56-
This allows you to start with minimal logging in production and increase verbosity (e.g., to `debug`) for deeper analysis when needed.
57-
58-
### Redirecting all logs to the console
59-
60-
Lucee 6.2 supports the following environment variables which allow overriding the log levels and appender, which is great for debugging and Docker
44+
Since Lucee 6.2, override log levels and appender via environment variables:
6145

6246
```bash
6347
LUCEE_LOGGING_FORCE_LEVEL=info
@@ -66,7 +50,7 @@ LUCEE_LOGGING_FORCE_APPENDER=console
6650

6751
### Adding or Modifying Logs
6852

69-
You can add, modify, or remove loggers in the **Lucee Administrator** or directly edit the `.CFConfig.json` file. Below is an example configuration:
53+
Configure in **Lucee Administrator** or `.CFConfig.json`:
7054

7155
```json
7256
"loggers": {
@@ -95,42 +79,30 @@ You can add, modify, or remove loggers in the **Lucee Administrator** or directl
9579
}
9680
```
9781

98-
### Internals: Powered by Log4j2
99-
100-
Lucee's logging system is powered by **Log4j2**, providing robust support for Appenders and Layouts.
101-
102-
You can extend Lucee logging by using any Appender or Layout supported by Log4j2.
82+
### Internals: Log4j2
10383

104-
---
84+
Powered by **Log4j2** - extend with any Log4j2 Appender or Layout.
10585

106-
## Built-in Support for Appenders and Layouts
86+
## Appenders and Layouts
10787

10888
### Built-in Appenders
10989

110-
Lucee comes with built-in support for the following Appenders:
111-
112-
- **console**: Logs output to the console, ideal for debugging in development or server environments.
113-
- **datasource**: Logs to a database table, allowing structured storage and querying of log data.
114-
- **resource**: Logs to a virtual filesystem endpoint, which can include local filesystems or external systems like **S3**, FTP, etc.
90+
- **console**: Output to console
91+
- **datasource**: Store in database table
92+
- **resource**: Write to virtual filesystem (local, S3, FTP, etc.)
11593

11694
### Built-in Layouts
11795

118-
Lucee also provides the following Layouts for customizing log output:
119-
120-
- **classic**: Produces traditional CFML-compatible output.
121-
- **datadog**: Formats logs for direct ingestion into **Datadog**.
122-
- **html**: Outputs logs in an HTML format suitable for browser-based debugging.
123-
- **json**: Generates logs in structured JSON format (uses Log4j2's JSONAppender internally).
124-
- **pattern**: Allows custom patterns for maximum flexibility.
125-
- **xml**: Outputs logs in structured XML format.
126-
127-
---
96+
- **classic**: Traditional CFML-compatible output
97+
- **datadog**: Datadog ingestion format
98+
- **html**: HTML format for browser debugging
99+
- **json**: Structured JSON (uses Log4j2's JSONAppender)
100+
- **pattern**: Custom patterns
101+
- **xml**: Structured XML
128102

129-
## Extending Logging with Custom Appenders and Layouts
103+
## Custom Appenders and Layouts
130104

131-
In addition to the built-in Appenders and Layouts, Lucee supports custom configurations using third-party libraries.
132-
133-
Here’s how you can define custom Appenders and Layouts:
105+
Extend with third-party libraries:
134106

135107
### Custom Appender Configuration
136108

@@ -171,29 +143,23 @@ Here’s how you can define custom Appenders and Layouts:
171143
}
172144
```
173145

174-
This configuration sends logs to a Kafka topic with a custom pattern Layout.
175-
176-
---
146+
Sends logs to a Kafka topic with custom pattern layout.
177147

178-
## Using the `<cflog>` Tag
148+
## Using `<cflog>`
179149

180-
Lucee supports logging through the `<cflog>` tag, which allows you to send log entries to specific loggers. The tag is available in both **HTML-style** and **script-style** syntax.
181-
182-
### Examples
183-
184-
#### HTML-Style Syntax
150+
### Tag Syntax
185151

186152
```html
187153
<cflog log="application" type="warn" text="Warning: Something went wrong!">
188154
```
189155

190-
#### Script-Style Syntax (Migration)
156+
### Script Syntax
191157

192158
```javascript
193159
log log="application" type="warn" text="Warning: Something went wrong!";
194160
```
195161

196-
#### Script-Style Syntax (Function)
162+
### Function Syntax
197163

198164
```javascript
199165
try {
@@ -204,8 +170,4 @@ catch(e) {
204170
}
205171
```
206172

207-
(Due to the existing math log function, the cf prefix is still required here, unlike with other tags in script.)
208-
209-
Lucee's `<cflog>` tag supports various attributes, including `log`, `type`, `text`, and `exception`. Using these attributes, you can customize log entries to suit your application's needs.
210-
211-
Lucee’s extensible logging framework offers flexibility for integrating with diverse infrastructures, enhancing monitoring, debugging, and auditing capabilities. By leveraging built-in features and custom configurations, you can adapt the logging system to your application's unique needs.
173+
Note: Due to the existing math `log` function, the `cf` prefix is required here unlike other tags in script.

docs/recipes/lucene-search.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@
2424

2525
# Lucene 3 Extension
2626

27-
The Lucene 3 Extension introduces significant enhancements to Lucee's search capabilities, including vector-based semantic search, hybrid search combining keyword and vector approaches, and improved content chunking for more relevant results.
27+
The Lucene 3 Extension brings modern search capabilities to Lucee, including vector-based semantic search that understands meaning rather than just matching keywords. You can use traditional keyword search, pure vector search, or combine both in hybrid mode for best results.
2828

29-
## Overview
29+
Key features:
3030

31-
Lucene 3 is a major update to Lucee's search functionality, bringing modern search techniques to your applications. This version introduces:
32-
33-
- Vector-based semantic search using document embeddings
34-
- Hybrid search combining traditional keyword search with vector search
35-
- Enhanced content chunking with passage extraction
36-
- Improved relevance scoring and result highlighting
37-
38-
These features enable more natural language understanding in search operations and provide better support for AI augmentation through Retrieval-Augmented Generation (RAG) patterns.
31+
- **Vector search** - find conceptually similar content using embeddings
32+
- **Hybrid search** - combine keyword and vector approaches
33+
- **Content chunking** - extract relevant passages for RAG (Retrieval-Augmented Generation) patterns
3934

4035
## Requirements
4136

docs/recipes/migrate.from.classic-to-modern-local-scope.md

Lines changed: 33 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,25 @@
1717

1818
# Migrating from Classic to Modern Local Scope Mode
1919

20-
Lucee offers two different modes for managing unscoped variables within functions: Classic and Modern.
20+
Lucee offers two modes for handling unscoped variables in functions: Classic and Modern.
2121

22-
This document explains the differences between these modes and provides a structured approach for migrating from Classic to Modern mode.
23-
24-
Simply switching to `localmode=true`, either per function or Application wide, will dramatically boost the performance of your Lucee applications, but requires testing.
22+
Switching to `localmode=true` (per function or application-wide) dramatically boosts performance, but requires testing.
2523

2624
## Understanding Local Scope Modes
2725

28-
The "Local scope mode" setting defines how variables with no explicit scope are handled within functions:
26+
The local scope mode setting defines how unscoped variables are handled in functions:
2927

30-
* **Classic Mode (CFML Default)**: Unscoped variables are stored in the variables scope, unless the key already exists in one of the function's local scopes (arguments or local).
31-
* **Modern Mode**: Unscoped variables are always stored in the local scope, regardless of whether they exist elsewhere.
28+
- **Classic Mode** (CFML default): Unscoped variables go to `variables` scope, unless the key exists in `arguments` or `local`.
29+
- **Modern Mode**: Unscoped variables always go to `local` scope.
3230

3331
## Why Migrate to Modern Mode?
3432

35-
Modern mode offers several advantages:
36-
37-
1. **Thread Safety**: Variables are isolated to the function instance, preventing race conditions when component instances are shared across requests.
38-
2. **Predictable Behavior**: All unscoped variables behave the same way, making code more intuitive and easier to maintain.
39-
3. **Performance**: Local scope lookups are typically faster than cascading scope resolution.
33+
- **Thread Safety**: Variables isolated to function instance - prevents race conditions with shared components
34+
- **Predictable Behavior**: All unscoped variables behave the same way
35+
- **Performance**: Local scope lookups are faster than cascading scope resolution
4036

4137
### Classic Mode Race Condition Example
4238

43-
Consider this component when running in Classic mode:
44-
4539
```cfml
4640
component {
4741
function createToken(id) {
@@ -52,39 +46,29 @@ component {
5246
}
5347
```
5448

55-
If this component is stored in application scope and used across multiple concurrent requests, `token` becomes a shared variable. This creates a race condition where multiple threads could overwrite each other's values.
49+
If this component is in application scope and used concurrently, `token` becomes shared - multiple threads can overwrite each other's values.
5650

5751
## Configuring Local Scope Mode
5852

59-
Local scope mode can be configured at several levels:
60-
61-
### 1. Server Level (Lucee Administrator)
53+
### Server Level (Lucee Administrator)
6254

63-
Under "Settings > Scope", set "Local scope mode" to either "Modern" or "Classic".
55+
Under "Settings > Scope", set "Local scope mode" to "Modern" or "Classic".
6456

65-
### 2. Server Configuration (.CFConfig.json)
57+
### Server Configuration (.CFConfig.json)
6658

6759
```json
6860
{
6961
"localScopeMode": "modern"
7062
}
7163
```
7264

73-
Or:
74-
75-
```json
76-
{
77-
"localScopeMode": "classic"
78-
}
79-
```
80-
81-
### 3. Application Level (Application.cfc)
65+
### Application Level (Application.cfc)
8266

8367
```cfml
8468
this.localMode = "modern"; // or "classic"
8569
```
8670

87-
### 4. Function Level
71+
### Function Level
8872

8973
```cfml
9074
function test() localMode="modern" {
@@ -94,29 +78,20 @@ function test() localMode="modern" {
9478

9579
## Migration Strategy: Using Cascading Write Logging
9680

97-
Switching directly to Modern mode may break existing applications that rely on Classic behavior. A safer approach is to:
81+
Switching directly to Modern mode may break existing applications. A safer approach:
9882

99-
1. Enable variable scope cascading write logging
100-
2. Identify and fix all occurrences of unscoped variables
83+
1. Enable cascading write logging
84+
2. Fix all unscoped variable occurrences
10185
3. Switch to Modern mode
10286

10387
### Step 1: Enable Cascading Write Logging
10488

105-
Set the following environment variables or system properties (This setting only applies to Lucee 6.2.1.82 and above):
106-
107-
**Environment Variable:** `LUCEE_CASCADING_WRITE_TO_VARIABLES_LOG`
108-
**System Property:** `-Dlucee.cascading.write.to.variables.log`
109-
110-
This specifies the log name where cascading write detections will be recorded.
111-
112-
You can also customize the log level (default is DEBUG):
113-
114-
**Environment Variable:** `LUCEE_CASCADING_WRITE_TO_VARIABLES_LOGLEVEL`
115-
**System Property:** `-Dlucee.cascading.write.to.variables.loglevel`
89+
Set environment variables or system properties (Lucee 6.2.1.82+):
11690

117-
Valid log levels include: DEBUG, INFO, WARN, ERROR.
91+
- `LUCEE_CASCADING_WRITE_TO_VARIABLES_LOG` / `-Dlucee.cascading.write.to.variables.log` - log name for detections
92+
- `LUCEE_CASCADING_WRITE_TO_VARIABLES_LOGLEVEL` / `-Dlucee.cascading.write.to.variables.loglevel` - log level (DEBUG, INFO, WARN, ERROR)
11893

119-
Example configuration:
94+
Example:
12095

12196
```
12297
# Environment variables
@@ -130,31 +105,22 @@ LUCEE_CASCADING_WRITE_TO_VARIABLES_LOGLEVEL=INFO
130105

131106
### Step 2: Analyze Logs and Modify Code
132107

133-
Monitor your application logs for entries like:
108+
Log entries look like:
134109

135110
```
136111
Variable Scope Cascading Write Detected: The variable [token] is being implicitly written to the variables scope at [MyComponent.cfc:42]. This occurs when no explicit scope (such as local, arguments, or variables) is specified in the assignment.
137112
```
138113

139-
For each occurrence, decide whether to:
114+
For each occurrence, add explicit scope:
140115

141-
1. **Add explicit `variables` scope** (if the variable should remain in the component's variables scope):
142-
143-
```cfml
144-
variables.token = createUUID();
145-
```
146-
147-
2. **Add explicit `local` scope** (if the variable should be function-local):
148-
149-
```cfml
150-
local.token = createUUID();
151-
```
116+
- `variables.token = createUUID();` - if it should remain component-level
117+
- `local.token = createUUID();` - if it should be function-local
152118

153119
### Common Patterns Requiring Attention
154120

155121
#### Component Properties
156122

157-
Properties meant to be stored at the component level need an explicit variables scope:
123+
Properties stored at the component level need explicit `variables` scope:
158124

159125
```cfml
160126
// Before
@@ -170,7 +136,7 @@ function init(datasourceName) {
170136

171137
#### Local Counters and Temporary Variables
172138

173-
Variables that should be local to a function call:
139+
Variables local to a function call:
174140

175141
```cfml
176142
// Before
@@ -196,31 +162,14 @@ function processItems(items) {
196162

197163
### Step 3: Test Thoroughly
198164

199-
After updating your code:
200-
201165
1. Test your application thoroughly
202-
2. Verify that all functionality works correctly
203-
3. Look for unexpected behaviors or errors
204-
4. Make sure you no longer get any log entries
166+
2. Verify all functionality works correctly
167+
3. Check for unexpected behaviors or errors
168+
4. Ensure no more log entries appear
205169

206170
### Step 4: Disable Logging and Switch to Modern Mode
207171

208-
Once all code has been updated and tested:
209-
210-
1. Disable the cascading write logging by removing the environment variables or system properties:
211-
212-
```
213-
# Remove environment variables
214-
unset LUCEE_CASCADING_WRITE_TO_VARIABLES_LOG
215-
unset LUCEE_CASCADING_WRITE_TO_VARIABLES_LOGLEVEL
216-
217-
# Or remove system properties from startup configuration
218-
# -Dlucee.cascading.write.to.variables.log
219-
# -Dlucee.cascading.write.to.variables.loglevel
220-
```
221-
222-
2. Switch to Modern mode at your preferred configuration level (server, application, or function).
223-
224-
## Conclusion
172+
Once all code is updated and tested:
225173

226-
Migrating to Modern mode improves thread safety and code predictability, but requires careful examination of existing code. Using cascading write logging helps identify potential issues before they become problems, allowing for a smooth transition.
174+
1. Remove the environment variables or system properties
175+
2. Switch to Modern mode at your preferred configuration level

0 commit comments

Comments
 (0)