@@ -1665,6 +1665,95 @@ export type HotBackupList = {
16651665 > ;
16661666} ;
16671667
1668+ /**
1669+ * Numeric representation of the logging level of a log entry.
1670+ */
1671+ export enum LogLevel {
1672+ FATAL ,
1673+ ERROR ,
1674+ WARNING ,
1675+ INFO ,
1676+ DEBUG ,
1677+ }
1678+
1679+ /**
1680+ * String representation of the logging level of a log entry.
1681+ */
1682+ export type LogLevelLabel = "FATAL" | "ERROR" | "WARNING" | "INFO" | "DEBUG" ;
1683+
1684+ /**
1685+ * Logging level setting.
1686+ */
1687+ export type LogLevelSetting = LogLevelLabel | "DEFAULT" ;
1688+
1689+ /**
1690+ * Log sorting direction, ascending or descending.
1691+ */
1692+ export type LogSortDirection = "asc" | "desc" ;
1693+
1694+ /**
1695+ * Options for retrieving log entries.
1696+ */
1697+ export type LogEntriesOptions = {
1698+ /**
1699+ * Maximum log level of the entries to retrieve.
1700+ *
1701+ * Default: `INFO`.
1702+ */
1703+ upto ?: LogLevel | LogLevelLabel | Lowercase < LogLevelLabel > ;
1704+ /**
1705+ * If set, only log entries with this log level will be returned.
1706+ */
1707+ level ?: LogLevel | LogLevelLabel | Lowercase < LogLevelLabel > ;
1708+ /**
1709+ * If set, only log entries with an `lid` greater than or equal to this value
1710+ * will be returned.
1711+ */
1712+ start ?: number ;
1713+ /**
1714+ * If set, only this many entries will be returned.
1715+ */
1716+ size ?: number ;
1717+ /**
1718+ * If set, this many log entries will be skipped.
1719+ */
1720+ offset ?: number ;
1721+ /**
1722+ * If set, only log entries containing the specified text will be returned.
1723+ */
1724+ search ?: string ;
1725+ /**
1726+ * If set to `"desc"`, log entries will be returned in reverse chronological
1727+ * order.
1728+ *
1729+ * Default: `"asc"`.
1730+ */
1731+ sort ?: LogSortDirection ;
1732+ } ;
1733+
1734+ /**
1735+ * An object representing a single log entry.
1736+ */
1737+ export type LogMessage = {
1738+ id : number ;
1739+ topic : string ;
1740+ level : LogLevelLabel ;
1741+ date : string ;
1742+ message : string ;
1743+ } ;
1744+
1745+ /**
1746+ * An object representing a list of log entries.
1747+ */
1748+ export type LogEntries = {
1749+ totalAmount : number ;
1750+ lid : number [ ] ;
1751+ topic : string [ ] ;
1752+ level : LogLevel [ ] ;
1753+ timestamp : number [ ] ;
1754+ text : string [ ] ;
1755+ } ;
1756+
16681757/**
16691758 * An object representing a single ArangoDB database. All arangojs collections,
16701759 * cursors, analyzers and so on are linked to a `Database` object.
@@ -5730,4 +5819,91 @@ export class Database {
57305819 ) ;
57315820 }
57325821 //#endregion
5822+ //#region logs
5823+ /**
5824+ * Retrieves the log messages from the server's global log.
5825+ *
5826+ * @param options - Options for retrieving the log entries.
5827+ *
5828+ * @example
5829+ * ```js
5830+ * const log = await db.getLogEntries();
5831+ * for (let i = 0; i < log.totalAmount; i++) {
5832+ * console.log(`${
5833+ * new Date(log.timestamp[i] * 1000).toISOString()
5834+ * } - [${LogLevel[log.level[i]]}] ${log.text[i]} (#${log.lid[i]})`);
5835+ * }
5836+ * ```
5837+ */
5838+ getLogEntries ( options ?: LogEntriesOptions ) : Promise < LogEntries > {
5839+ return this . request (
5840+ {
5841+ path : "/_admin/log" ,
5842+ qs : options ,
5843+ } ,
5844+ ( res ) => res . body
5845+ ) ;
5846+ }
5847+
5848+ /**
5849+ * Retrieves the log messages from the server's global log.
5850+ *
5851+ * @param options - Options for retrieving the log entries.
5852+ *
5853+ * @example
5854+ * ```js
5855+ * const messages = await db.getLogMessages();
5856+ * for (const m of messages) {
5857+ * console.log(`${m.date} - [${m.level}] ${m.message} (#${m.id})`);
5858+ * }
5859+ * ```
5860+ */
5861+ getLogMessages ( options ?: LogEntriesOptions ) : Promise < LogMessage [ ] > {
5862+ return this . request (
5863+ {
5864+ path : "/_admin/log" ,
5865+ qs : options ,
5866+ } ,
5867+ ( res ) => res . body . messages
5868+ ) ;
5869+ }
5870+
5871+ /**
5872+ * Retrieves the server's current log level for each topic.
5873+ *
5874+ * @example
5875+ * ```js
5876+ * const levels = await db.getLogLevel();
5877+ * console.log(levels.request); // log level for incoming requests
5878+ * ```
5879+ */
5880+ getLogLevel ( ) : Promise < Record < string , LogLevelSetting > > {
5881+ return this . request ( {
5882+ path : "/_admin/log/level" ,
5883+ } ) ;
5884+ }
5885+
5886+ /**
5887+ * Sets the server's log level for each of the given topics to the given level.
5888+ *
5889+ * Any omitted topics will be left unchanged.
5890+ *
5891+ * @param levels - An object mapping topic names to log levels.
5892+ *
5893+ * @example
5894+ * ```js
5895+ * await db.setLogLevel({ request: "debug" });
5896+ * // Debug information will now be logged for each request
5897+ * ```
5898+ */
5899+ setLogLevel (
5900+ levels : Record < string , LogLevelSetting >
5901+ ) : Promise < Record < string , LogLevelSetting > > {
5902+ return this . request ( {
5903+ method : "PUT" ,
5904+ path : "/_admin/log/level" ,
5905+ body : levels ,
5906+ } ) ;
5907+ }
5908+ //#endregion
57335909}
0 commit comments