Class LogsResource
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable,BasicUniversalConfig,DefaultConfig,DefaultHtmlConfig
Routes
| Request | Does |
|---|---|
GET /logs/{path} | Information on a file, or a directory listing |
GET /logs/view/{path} | The file's contents as text, or as HTML with ?highlight=true |
GET /logs/parse/{path} | The file's parsed log entries |
GET /logs/download/{path} | The file's contents as application/octet-stream |
DELETE /logs/{path} | Deletes the file or directory, when Logging/allowDeletes is on |
The view, parse and download prefixes are reserved: they always name an action, never a
directory. A log directory with one of those names cannot be listed through GET /logs/view and so on, but
its files are still reachable through the action routes, for example GET /logs/view/view/app.log. The
listing's link to such a directory routes to the action and is answered with 404, as is any action on a
directory. DELETE reserves no prefix: DELETE /logs/view/app.log deletes app.log in the
view directory.
Every read is a plain GET, and the method query parameter is not accepted, so no GET link
can delete anything. A delete must be a real DELETE, sent by a REST client or from the command line; the
HTML listing has no delete link, because a browser link or form cannot carry the header-borne token a CSRF
boundary requires. A DELETE cannot be sent cross-site without a CORS preflight, so a boundary in front of
this resource (see AdminBoundary) admits it without a token:
curl -X DELETE http://localhost:10000/logs/old.log
This resource has no authentication of its own. Do not expose it on an untrusted network.
See Also:
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFile action link.static classFile or directory details for REST response.Nested classes/interfaces inherited from class org.apache.juneau.rest.server.servlet.RestServlet
RestServlet.Builder<R extends RestServlet,SELF extends RestServlet.Builder<R, SELF>>, RestServlet.DefaultBuilder<R extends RestServlet> -
Field Summary
Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.juneau.microservice.examples.LogsResource.RedirectToRootdeleteFile(String path) Deletes a log file on the file system.org.apache.juneau.microservice.examples.LogsResource.FileContentsdownloadFile(RestResponse res, String path) Downloads the contents of a file.getFile(RestRequest req, String path) Returns information about the specified file or directory.voidInitializes log directory and formatter from config.voidviewFile(RestResponse res, String path, boolean highlight, String start, String end, String thread, String[] loggers, String[] severity) Views the contents of a log file with optional filtering.viewParsedEntries(RestRequest req, String path, String start, String end, String thread, String[] loggers, String[] severity) Views the parsed contents of a log file with filtering.Methods inherited from class org.apache.juneau.rest.server.servlet.RestServlet
builder, createAuthenticator, destroy, doLog, getContext, getPath, getPaths, getRequest, getResponse, getRestBuilder, init, log, log, service, setContextMethods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPatch, doPost, doPut, doTrace, getLastModified, isSensitiveHeader, serviceMethods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
LogsResource
public LogsResource()
-
-
Method Details
-
deleteFile
public org.apache.juneau.microservice.examples.LogsResource.RedirectToRoot deleteFile(@Path("/*") String path) throws MethodNotAllowed Deletes a log file on the file system.- Parameters:
path- The file path.- Returns:
- Redirect to root on success.
- Throws:
MethodNotAllowed- If deletes are not enabled.
-
downloadFile
public org.apache.juneau.microservice.examples.LogsResource.FileContents downloadFile(RestResponse res, @Path("/*") String path) throws NotFound Downloads the contents of a file.- Parameters:
res- The response.path- The file path.- Returns:
- The file contents stream.
- Throws:
NotFound- If the file is not found, or is a directory.
-
getFile
public LogsResource.FileResource getFile(RestRequest req, @Path("/*") String path) throws NotFound, Exception Returns information about the specified file or directory. -
init
Initializes log directory and formatter from config.- Parameters:
config- The microservice configuration.
-
viewFile
public void viewFile(RestResponse res, @Path("/*") String path, @Query(name="highlight",schema=@Schema(d="Add severity color highlighting.")) boolean highlight, @Query(name="start",schema=@Schema(d="Start timestamp (ISO8601, full or partial).\nDon\'t print lines logged before the specified timestamp.\nUse any of the following formats: yyyy, yyyy-MM, yyyy-MM-dd, yyyy-MM-ddThh, yyyy-MM-ddThh:mm, yyyy-MM-ddThh:mm:ss, yyyy-MM-ddThh:mm:ss.SSS")) String start, @Query(name="end",schema=@Schema(d="End timestamp (ISO8601, full or partial).\nDon\'t print lines logged after the specified timestamp.\nUse any of the following formats: yyyy, yyyy-MM, yyyy-MM-dd, yyyy-MM-ddThh, yyyy-MM-ddThh:mm, yyyy-MM-ddThh:mm:ss, yyyy-MM-ddThh:mm:ss.SSS")) String end, @Query(name="thread",schema=@Schema(d="Thread name filter.\nOnly show log entries with the specified thread name.")) String thread, @Query(name="loggers",schema=@Schema(d="Logger filter (simple class name).\nOnly show log entries if they were produced by one of the specified loggers.")) String[] loggers, @Query(name="severity",schema=@Schema(d="Severity filter.\nOnly show log entries with the specified severity.")) String[] severity) throws NotFound, IOException Views the contents of a log file with optional filtering.- Parameters:
res- The response.path- The file path.highlight- Add severity color highlighting.start- Start timestamp filter.end- End timestamp filter.thread- Thread name filter.loggers- Logger filter.severity- Severity filter.- Throws:
NotFound- If the file is not found, or is a directory.IOException- If an I/O error occurs.
-
viewParsedEntries
public LogParser viewParsedEntries(RestRequest req, @Path("/*") String path, @Query(name="start",schema=@Schema(d="Start timestamp (ISO8601, full or partial).\nDon\'t print lines logged before the specified timestamp.\nUse any of the following formats: yyyy, yyyy-MM, yyyy-MM-dd, yyyy-MM-ddThh, yyyy-MM-ddThh:mm, yyyy-MM-ddThh:mm:ss, yyyy-MM-ddThh:mm:ss.SSS")) String start, @Query(name="end",schema=@Schema(d="End timestamp (ISO8601, full or partial).\nDon\'t print lines logged after the specified timestamp.\nUse any of the following formats: yyyy, yyyy-MM, yyyy-MM-dd, yyyy-MM-ddThh, yyyy-MM-ddThh:mm, yyyy-MM-ddThh:mm:ss, yyyy-MM-ddThh:mm:ss.SSS")) String end, @Query(name="thread",schema=@Schema(d="Thread name filter.\nOnly show log entries with the specified thread name.")) String thread, @Query(name="loggers",schema=@Schema(d="Logger filter (simple class name).\nOnly show log entries if they were produced by one of the specified loggers.")) String[] loggers, @Query(name="severity",schema=@Schema(d="Severity filter.\nOnly show log entries with the specified severity.")) String[] severity) throws NotFound, IOException Views the parsed contents of a log file with filtering.- Parameters:
req- The request.path- The file path.start- Start timestamp filter.end- End timestamp filter.thread- Thread name filter.loggers- Logger filter.severity- Severity filter.- Returns:
- The log parser iterable.
- Throws:
NotFound- If the file is not found.IOException- If an I/O error occurs.
-