mirror of
https://github.com/misskey-dev/SyslogPro.git
synced 2025-04-29 02:37:18 +09:00
Merge pull request #9 from zeit/timestamps-default-remove-timequality
Fix timestamps default, remove timeQuality structured data and remove includeStructureData option
This commit is contained in:
commit
e8cf9d4cdd
56
index.ts
56
index.ts
@ -998,7 +998,6 @@ type RFC5424Options = {
|
|||||||
};
|
};
|
||||||
extendedColor?: boolean;
|
extendedColor?: boolean;
|
||||||
hostname?: string;
|
hostname?: string;
|
||||||
includeStructuredData?: boolean;
|
|
||||||
server?: Syslog | SyslogOptions;
|
server?: Syslog | SyslogOptions;
|
||||||
timestamp?: boolean;
|
timestamp?: boolean;
|
||||||
timestampMS?: boolean;
|
timestampMS?: boolean;
|
||||||
@ -1027,7 +1026,6 @@ export class RFC5424 extends RFC {
|
|||||||
applicationName: string;
|
applicationName: string;
|
||||||
color: boolean;
|
color: boolean;
|
||||||
hostname: string;
|
hostname: string;
|
||||||
includeStructuredData: boolean;
|
|
||||||
server: Syslog;
|
server: Syslog;
|
||||||
timestamp: boolean;
|
timestamp: boolean;
|
||||||
timestampMS: boolean;
|
timestampMS: boolean;
|
||||||
@ -1041,15 +1039,13 @@ export class RFC5424 extends RFC {
|
|||||||
* @param {object} [options] - Options object
|
* @param {object} [options] - Options object
|
||||||
* @param {string} [options.applicationName='NodeJSLogger'] - Application
|
* @param {string} [options.applicationName='NodeJSLogger'] - Application
|
||||||
* @param {string} [options.hostname=os.hostname] - The name of this server
|
* @param {string} [options.hostname=os.hostname] - The name of this server
|
||||||
* @param {boolean} [options.timestamp=false] - Included a Timestamp
|
* @param {boolean} [options.timestamp=true] - Included a Timestamp
|
||||||
* @param {boolean} [options.timestampUTC=false] - RFC standard is for
|
* @param {boolean} [options.timestampUTC=true] - RFC standard is for
|
||||||
* local time
|
* local time
|
||||||
* @param {boolean} [options.timestampMS=false] - Timestamp with ms
|
* @param {boolean} [options.timestampMS=true] - Timestamp with ms
|
||||||
* resolution
|
* resolution
|
||||||
* @param {boolean} [options.timestampTZ=true] - Should the timestamp
|
* @param {boolean} [options.timestampTZ=true] - Should the timestamp
|
||||||
* included time zone
|
* included time zone
|
||||||
* @param {boolean} [options.includeStructuredData=false] - Included
|
|
||||||
* any provided structured data
|
|
||||||
* @param {boolean} [options.utf8BOM=true] - Included the UTF8
|
* @param {boolean} [options.utf8BOM=true] - Included the UTF8
|
||||||
* @param {boolean} [options.color=false] - Included the UTF8
|
* @param {boolean} [options.color=false] - Included the UTF8
|
||||||
* @param {boolean} [options.extendedColor=false] - Included the UTF8
|
* @param {boolean} [options.extendedColor=false] - Included the UTF8
|
||||||
@ -1089,36 +1085,10 @@ export class RFC5424 extends RFC {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
this.hostname = options.hostname || os.hostname();
|
this.hostname = options.hostname || os.hostname();
|
||||||
this.applicationName = options.applicationName || '';
|
this.applicationName = options.applicationName || '';
|
||||||
if (typeof options.timestamp === 'undefined' || options.timestamp) {
|
this.timestamp = options.timestamp !== false;
|
||||||
/** @type {boolean} */
|
this.timestampMS = options.timestampMS !== false;
|
||||||
this.timestamp = true;
|
this.timestampTZ = options.timestampTZ !== false;
|
||||||
} else {
|
this.timestampUTC = options.timestampUTC !== false;
|
||||||
this.timestamp = false;
|
|
||||||
}
|
|
||||||
if (options.timestampUTC) {
|
|
||||||
/** @type {boolean} */
|
|
||||||
this.timestampUTC = true;
|
|
||||||
} else {
|
|
||||||
this.timestampUTC = false;
|
|
||||||
}
|
|
||||||
if (typeof options.timestampTZ === 'undefined' || options.timestampTZ) {
|
|
||||||
/** @type {boolean} */
|
|
||||||
this.timestampTZ = true;
|
|
||||||
} else {
|
|
||||||
this.timestampTZ = false;
|
|
||||||
}
|
|
||||||
if (options.timestampMS) {
|
|
||||||
/** @type {boolean} */
|
|
||||||
this.timestampMS = true;
|
|
||||||
} else {
|
|
||||||
this.timestampMS = false;
|
|
||||||
}
|
|
||||||
if (options.includeStructuredData) {
|
|
||||||
/** @type {boolean} */
|
|
||||||
this.includeStructuredData = true;
|
|
||||||
} else {
|
|
||||||
this.includeStructuredData = false;
|
|
||||||
}
|
|
||||||
if (typeof options.utf8BOM === 'undefined' || options.utf8BOM) {
|
if (typeof options.utf8BOM === 'undefined' || options.utf8BOM) {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
this.utf8BOM = true;
|
this.utf8BOM = true;
|
||||||
@ -1241,9 +1211,7 @@ export class RFC5424 extends RFC {
|
|||||||
// RFC5424 timestamp formating
|
// RFC5424 timestamp formating
|
||||||
let timestamp = '-';
|
let timestamp = '-';
|
||||||
if (this.timestamp || options.timestamp) {
|
if (this.timestamp || options.timestamp) {
|
||||||
let timeQuality = '[timeQuality';
|
|
||||||
if (this.timestampUTC) {
|
if (this.timestampUTC) {
|
||||||
timeQuality += ' tzKnown=1';
|
|
||||||
if (this.timestampMS) {
|
if (this.timestampMS) {
|
||||||
if (this.timestampTZ) {
|
if (this.timestampTZ) {
|
||||||
timestamp = moment(options.timestamp)
|
timestamp = moment(options.timestamp)
|
||||||
@ -1267,10 +1235,7 @@ export class RFC5424 extends RFC {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.timestampTZ) {
|
if (this.timestampTZ) {
|
||||||
timeQuality += ' tzKnown=1';
|
|
||||||
if (this.timestampMS) {
|
if (this.timestampMS) {
|
||||||
timeQuality += ' isSynced=1';
|
|
||||||
timeQuality += ' syncAccuracy=0';
|
|
||||||
timestamp = moment(options.timestamp)
|
timestamp = moment(options.timestamp)
|
||||||
.format('YYYY-MM-DDThh:mm:ss.SSSZ');
|
.format('YYYY-MM-DDThh:mm:ss.SSSZ');
|
||||||
} else {
|
} else {
|
||||||
@ -1278,10 +1243,7 @@ export class RFC5424 extends RFC {
|
|||||||
.format('YYYY-MM-DDThh:mm:ssZ');
|
.format('YYYY-MM-DDThh:mm:ssZ');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
timeQuality += ' tzKnown=0';
|
|
||||||
if (this.timestampMS) {
|
if (this.timestampMS) {
|
||||||
timeQuality += ' isSynced=1';
|
|
||||||
timeQuality += ' syncAccuracy=0';
|
|
||||||
timestamp = moment(options.timestamp)
|
timestamp = moment(options.timestamp)
|
||||||
.format('YYYY-MM-DDThh:mm:ss.SSS');
|
.format('YYYY-MM-DDThh:mm:ss.SSS');
|
||||||
} else {
|
} else {
|
||||||
@ -1289,13 +1251,11 @@ export class RFC5424 extends RFC {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
timeQuality += ']';
|
|
||||||
msgStructuredData.push(timeQuality);
|
|
||||||
}
|
}
|
||||||
// Build Structured Data string
|
// Build Structured Data string
|
||||||
let structuredData = '-';
|
let structuredData = '-';
|
||||||
const sdElementCount = msgStructuredData.length;
|
const sdElementCount = msgStructuredData.length;
|
||||||
if (this.includeStructuredData && sdElementCount > 0) {
|
if (sdElementCount > 0) {
|
||||||
let sdElementNames = [];
|
let sdElementNames = [];
|
||||||
let sdElements = [];
|
let sdElements = [];
|
||||||
const sdElementNameRegEx = /(\[)(\S*)(\s|\])/;
|
const sdElementNameRegEx = /(\[)(\S*)(\s|\])/;
|
||||||
|
@ -279,7 +279,6 @@ describe('RFC5424 Class Tests', () => {
|
|||||||
timestampUTC: true,
|
timestampUTC: true,
|
||||||
timestampTZ: false,
|
timestampTZ: false,
|
||||||
timestampMS: true,
|
timestampMS: true,
|
||||||
includeStructuredData: true,
|
|
||||||
colors: {
|
colors: {
|
||||||
emergencyColor: 30,
|
emergencyColor: 30,
|
||||||
alertColor: 30,
|
alertColor: 30,
|
||||||
@ -328,7 +327,6 @@ describe('RFC5424 Class Tests', () => {
|
|||||||
let resultMsg = /<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2} /;
|
let resultMsg = /<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2} /;
|
||||||
expect(result).toMatch(resultMsg);
|
expect(result).toMatch(resultMsg);
|
||||||
rfc5424 = new SyslogPro.RFC5424({
|
rfc5424 = new SyslogPro.RFC5424({
|
||||||
includeStructuredData: true,
|
|
||||||
color: true,
|
color: true,
|
||||||
extendedColor: false,
|
extendedColor: false,
|
||||||
timestamp: true,
|
timestamp: true,
|
||||||
@ -417,7 +415,7 @@ describe('RFC5424 Class Tests', () => {
|
|||||||
hostname: 'hostname',
|
hostname: 'hostname',
|
||||||
applicationName: 'applicationName'
|
applicationName: 'applicationName'
|
||||||
});
|
});
|
||||||
expect(result).toMatch(/^<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2} hostname applicationName - - - BOMhello\n$/);
|
expect(result).toMatch(/^<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,3}[\+\-]\d{2}:\d{2} hostname applicationName - - - BOMhello\n$/);
|
||||||
});
|
});
|
||||||
test('RFC5424 SetColors', () => {
|
test('RFC5424 SetColors', () => {
|
||||||
let rfc5424 = new SyslogPro.RFC5424();
|
let rfc5424 = new SyslogPro.RFC5424();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user