You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Developer_Guide.md
+87-1Lines changed: 87 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -363,4 +363,90 @@ global with sharing class CustomerWebServiceDemo {
363
363
364
364
> **_NOTE:_** In this example We've put the rest processors as a subclasses in owr web service just to simplify reading the code but feel free to keep them as independent classes.
365
365
366
-
# Advanced Topics
366
+
# Advanced Topics
367
+
368
+
## Logging REST Requests with libak_RestFramework
369
+
370
+
By default, the REST Framework does not log any requests. However, logging can be enabled with a few simple steps, allowing you to capture detailed information about each REST request and its lifecycle. This guide outlines how to implement logging using the framework's extensibility.
371
+
372
+
---
373
+
374
+
### Enabling Logging
375
+
To enable logging, follow these steps:
376
+
377
+
### 1. Implement the `libak_IRestLogger` Interface
378
+
The `libak_IRestLogger` interface defines three methods that you must implement to customize logging behavior.
379
+
380
+
#### Methods Overview
381
+
-**`void initLog(RestRequest request)`**
382
+
Used for initializing log entries with details about the incoming request.
383
+
-**`void addErrorDetails(Exception exc)`**
384
+
Captures and adds error information to the log.
385
+
-**`void createLog()`**
386
+
Finalizes and persists the log entry (e.g., inserts a database record or writes to an external system).
387
+
388
+
### 2. Inject Logging Dependency
389
+
Pass your logger class when invoking `libak_RestFramework.handleRequest`.
390
+
391
+
---
392
+
393
+
### Step 1: Create a Logger Class
394
+
Define a new class implementing the `libak_IRestLogger` interface.
395
+
396
+
```java
397
+
public with sharing classRestLoggerimplements libak_IRestLogger {
398
+
publicvoidinitLog(RestRequestrequest) {
399
+
// Initialize a log entry with details from the incoming REST request.
400
+
}
401
+
402
+
publicvoidaddErrorDetails(Exceptionexc) {
403
+
// Add error-specific details to the log entry.
404
+
}
405
+
406
+
publicvoidcreateLog() {
407
+
// Finalize and save the log entry.
408
+
}
409
+
}
410
+
```
411
+
412
+
---
413
+
414
+
### Step 2: Update the HTTP Methods
415
+
Modify your REST Web Service class to enable logging. Pass your custom logger class as a dependency in the `handleRequest` method.
After completing these steps, the REST Framework will invoke your `RestLogger` implementation for every incoming request. The logger will:
443
+
- Record request details during the `initLog` method.
444
+
- Append error information in the event of an exception via the `addErrorDetails` method.
445
+
- Save the log (e.g., as a Salesforce record) when the `createLog` method is called.
446
+
447
+
This flexible approach lets you tailor logging to meet your organization’s auditing, debugging, or monitoring requirements.
448
+
449
+
---
450
+
451
+
### Conclusion
452
+
By implementing the `libak_IRestLogger` interface and injecting your logger class into the request-handling pipeline, you gain full control over how REST requests are logged. This setup ensures your system captures the information you need for effective troubleshooting and operational visibility.
0 commit comments