fix(core): update
This commit is contained in:
parent
b0cf4bb27f
commit
ad24ba2f5d
@ -10,9 +10,9 @@ tap.test('first test', async () => {
|
|||||||
testElasticLog = new elasticsearch.ElasticSearch({
|
testElasticLog = new elasticsearch.ElasticSearch({
|
||||||
indexPrefix: 'smartlog',
|
indexPrefix: 'smartlog',
|
||||||
indexRetention: 7,
|
indexRetention: 7,
|
||||||
domain: testQenv.getEnvVarOnDemand('ELK_DOMAIN'),
|
node: testQenv.getEnvVarOnDemand('ELK_DOMAIN'),
|
||||||
port: parseInt(testQenv.getEnvVarOnDemand('ELK_PORT'), 10),
|
user: '',
|
||||||
ssl: true,
|
pass: '',
|
||||||
});
|
});
|
||||||
expect(testElasticLog).toBeInstanceOf(elasticsearch.ElasticSearch);
|
expect(testElasticLog).toBeInstanceOf(elasticsearch.ElasticSearch);
|
||||||
});
|
});
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@apiclient.xyz/elasticsearch',
|
name: '@apiclient.xyz/elasticsearch',
|
||||||
version: '1.0.39',
|
version: '1.0.40',
|
||||||
description: 'log to elasticsearch in a kibana compatible format'
|
description: 'log to elasticsearch in a kibana compatible format'
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,7 @@ export interface IStandardLogParams {
|
|||||||
export interface IElasticSearchConstructorOptions {
|
export interface IElasticSearchConstructorOptions {
|
||||||
indexPrefix: string;
|
indexPrefix: string;
|
||||||
indexRetention: number;
|
indexRetention: number;
|
||||||
port: number;
|
node: string;
|
||||||
domain: string;
|
|
||||||
ssl: boolean;
|
|
||||||
user?: string;
|
user?: string;
|
||||||
pass?: string;
|
pass?: string;
|
||||||
}
|
}
|
||||||
@ -35,31 +33,16 @@ export class ElasticSearch<T> {
|
|||||||
*/
|
*/
|
||||||
constructor(optionsArg: IElasticSearchConstructorOptions) {
|
constructor(optionsArg: IElasticSearchConstructorOptions) {
|
||||||
this.client = new ElasticClient({
|
this.client = new ElasticClient({
|
||||||
node: this.computeHostString(optionsArg),
|
node: optionsArg.node,
|
||||||
// log: 'trace'
|
auth: {
|
||||||
|
username: optionsArg.user,
|
||||||
|
password: optionsArg.pass,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.indexPrefix = optionsArg.indexPrefix;
|
this.indexPrefix = optionsArg.indexPrefix;
|
||||||
this.indexRetention = optionsArg.indexRetention;
|
this.indexRetention = optionsArg.indexRetention;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* computes the host string from the constructor options
|
|
||||||
* @param optionsArg
|
|
||||||
*/
|
|
||||||
private computeHostString(optionsArg: IElasticSearchConstructorOptions): string {
|
|
||||||
let hostString = `${optionsArg.domain}:${optionsArg.port}`;
|
|
||||||
if (optionsArg.user && optionsArg.pass) {
|
|
||||||
hostString = `${optionsArg.user}:${optionsArg.pass}@${hostString}`;
|
|
||||||
}
|
|
||||||
if (optionsArg.ssl) {
|
|
||||||
hostString = `https://${hostString}`;
|
|
||||||
} else {
|
|
||||||
hostString = `http://${hostString}`;
|
|
||||||
}
|
|
||||||
console.log(hostString);
|
|
||||||
return hostString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async log(logPackageArg: ILogPackage, scheduleOverwrite = false) {
|
public async log(logPackageArg: ILogPackage, scheduleOverwrite = false) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const indexToUse = `${this.indexPrefix}-${now.getFullYear()}.${(
|
const indexToUse = `${this.indexPrefix}-${now.getFullYear()}.${(
|
||||||
|
Loading…
Reference in New Issue
Block a user