Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ Expects the following parameters:

Returns [`Promise<HTTP.Body>`](#body)

#### <a name="logs">`server.logs(conn)`</a>

Retrieves a zip file containing log information for an endpoint.

Expects the following parameters:

- conn ([`Connection`](#connection))

Returns [`Promise<Response>`](#response)

## <a name="db">db</a>

#### <a name="create">`db.create(conn, database, databaseOptions, options, params)`</a>
Expand Down
5 changes: 5 additions & 0 deletions lib/index.d.ts
Comment thread
jakehamilton marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ declare namespace Stardog {
* properties, but you can specify `names` to return specific ones.
*/
function properties(conn: Connection, names?: string[]): Promise<HTTP.Body>;

/**
* Retrieves a zip file containing log information for an endpoint.
*/
function logs(conn: Connection): Promise<Response>;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Decided to use a plain Response object here instead of returning a Blob or ArrayBuffer to give the consumer the freedom to handle that as they see fit. Some use cases might be easier as one or the other and they're accessed simply enough from the response object like normal:

const blob = await stardog.server.logs().blob()

// or

const buffer = await stardog.server.logs().arrayBuffer()

}

/** Stardog database actions. */
Expand Down
10 changes: 10 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,18 @@ const properties = (conn, names = []) => {
).then(httpBody);
};

const logs = conn => {
const headers = conn.headers();
const response = fetch(conn.request('admin', 'logs'), {
headers,
});

return response;
};

module.exports = {
shutdown,
status,
properties,
logs,
};
22 changes: 22 additions & 0 deletions test/serverLogs.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-env jest */

const { server } = require('../lib');
const { ConnectionFactory } = require('./setup-database');

describe('server.logs()', () => {
let conn;

beforeEach(() => {
conn = ConnectionFactory();
});

it('should retrieve a JS response object containing the logs zip file', () =>
server.logs(conn).then(response => {
expect(response.status).toBe(200);

return response.arrayBuffer().then(buffer => {
expect(buffer).toBeTruthy();
expect(buffer.byteLength).toBeGreaterThan(0);
});
}));
});