mirror of
https://github.com/misskey-dev/SyslogPro.git
synced 2025-04-29 02:37:18 +09:00
use ISO date string and Z (zulu timezone) for UTC
This commit is contained in:
parent
16d7736127
commit
7940e1f17c
6
index.ts
6
index.ts
@ -1390,9 +1390,7 @@ export class RFC5424 extends RFC {
|
|||||||
if (this.timestampUTC) {
|
if (this.timestampUTC) {
|
||||||
if (this.timestampMS) {
|
if (this.timestampMS) {
|
||||||
if (this.timestampTZ) {
|
if (this.timestampTZ) {
|
||||||
timestamp = moment(options.timestamp)
|
timestamp = moment(options.timestamp).toISOString();
|
||||||
.utc()
|
|
||||||
.format('YYYY-MM-DDThh:mm:ss.SSSZ');
|
|
||||||
} else {
|
} else {
|
||||||
timestamp = moment(options.timestamp)
|
timestamp = moment(options.timestamp)
|
||||||
.utc()
|
.utc()
|
||||||
@ -1402,7 +1400,7 @@ export class RFC5424 extends RFC {
|
|||||||
if (this.timestampTZ) {
|
if (this.timestampTZ) {
|
||||||
timestamp = moment(options.timestamp)
|
timestamp = moment(options.timestamp)
|
||||||
.utc()
|
.utc()
|
||||||
.format('YYYY-MM-DDThh:mm:ssZ');
|
.format('YYYY-MM-DDThh:mm:ss[Z]');
|
||||||
} else {
|
} else {
|
||||||
timestamp = moment(options.timestamp)
|
timestamp = moment(options.timestamp)
|
||||||
.utc()
|
.utc()
|
||||||
|
@ -335,7 +335,7 @@ describe('RFC5424 Class Tests', () => {
|
|||||||
test('RFC5424 BuildMessage with no message', () => {
|
test('RFC5424 BuildMessage with no message', () => {
|
||||||
const rfc5424 = new SyslogPro.RFC5424({ hostname: '-' });
|
const rfc5424 = new SyslogPro.RFC5424({ hostname: '-' });
|
||||||
const result = rfc5424.buildMessage();
|
const result = rfc5424.buildMessage();
|
||||||
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} - - - - -\n$/);
|
expect(result).toMatch(/^<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,3}Z - - - - -\n$/);
|
||||||
});
|
});
|
||||||
test('RFC5424 BuildMessage with Timestamp options', () => {
|
test('RFC5424 BuildMessage with Timestamp options', () => {
|
||||||
let rfc5424 = new SyslogPro.RFC5424({
|
let rfc5424 = new SyslogPro.RFC5424({
|
||||||
@ -383,7 +383,7 @@ describe('RFC5424 Class Tests', () => {
|
|||||||
timestampMS: true,
|
timestampMS: true,
|
||||||
});
|
});
|
||||||
result = rfc5424.buildMessage('hello');
|
result = rfc5424.buildMessage('hello');
|
||||||
resultMsg = /<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{1,3}\+/;
|
resultMsg = /<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{1,3}[\+\-]\d{2}:\d{2}/;
|
||||||
expect(result).toMatch(resultMsg);
|
expect(result).toMatch(resultMsg);
|
||||||
rfc5424 = new SyslogPro.RFC5424({
|
rfc5424 = new SyslogPro.RFC5424({
|
||||||
timestamp: true,
|
timestamp: true,
|
||||||
@ -392,7 +392,7 @@ describe('RFC5424 Class Tests', () => {
|
|||||||
timestampMS: false,
|
timestampMS: false,
|
||||||
});
|
});
|
||||||
result = rfc5424.buildMessage('hello');
|
result = rfc5424.buildMessage('hello');
|
||||||
resultMsg = /<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+/;
|
resultMsg = /<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[\+\-]\d{2}:\d{2}/;
|
||||||
expect(result).toMatch(resultMsg);
|
expect(result).toMatch(resultMsg);
|
||||||
rfc5424 = new SyslogPro.RFC5424({
|
rfc5424 = new SyslogPro.RFC5424({
|
||||||
timestamp: true,
|
timestamp: true,
|
||||||
@ -419,7 +419,7 @@ describe('RFC5424 Class Tests', () => {
|
|||||||
timestampMS: true,
|
timestampMS: true,
|
||||||
});
|
});
|
||||||
result = rfc5424.buildMessage('hello');
|
result = rfc5424.buildMessage('hello');
|
||||||
resultMsg = /<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{1,3}\+/;
|
resultMsg = /<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{1,3}Z/;
|
||||||
expect(result).toMatch(resultMsg);
|
expect(result).toMatch(resultMsg);
|
||||||
rfc5424 = new SyslogPro.RFC5424({
|
rfc5424 = new SyslogPro.RFC5424({
|
||||||
timestamp: true,
|
timestamp: true,
|
||||||
@ -428,7 +428,7 @@ describe('RFC5424 Class Tests', () => {
|
|||||||
timestampMS: false,
|
timestampMS: false,
|
||||||
});
|
});
|
||||||
result = rfc5424.buildMessage('hello');
|
result = rfc5424.buildMessage('hello');
|
||||||
resultMsg = /<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+/;
|
resultMsg = /<190>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/;
|
||||||
expect(result).toMatch(resultMsg);
|
expect(result).toMatch(resultMsg);
|
||||||
});
|
});
|
||||||
test('RFC5424 BuildMessage with Timestamp options to set date', () => {
|
test('RFC5424 BuildMessage with Timestamp options to set date', () => {
|
||||||
@ -440,7 +440,7 @@ describe('RFC5424 Class Tests', () => {
|
|||||||
});
|
});
|
||||||
const timestamp = new Date('2020-01-01T01:23:45.678Z');
|
const timestamp = new Date('2020-01-01T01:23:45.678Z');
|
||||||
const result = rfc5424.buildMessage('hello', { timestamp });
|
const result = rfc5424.buildMessage('hello', { timestamp });
|
||||||
expect(result.startsWith('<190>1 2020-01-01T01:23:45.678+00:00 ')).toBe(true);
|
expect(result.startsWith('<190>1 2020-01-01T01:23:45.678Z ')).toBe(true);
|
||||||
});
|
});
|
||||||
test('RFC5424 BuildMessage with hostname and applicationName options', () => {
|
test('RFC5424 BuildMessage with hostname and applicationName options', () => {
|
||||||
const rfc5424 = new SyslogPro.RFC5424();
|
const rfc5424 = new SyslogPro.RFC5424();
|
||||||
@ -448,7 +448,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{1,3}[\+\-]\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}Z hostname applicationName - - - BOMhello\n$/);
|
||||||
});
|
});
|
||||||
test('RFC5424 BuildMessage with structredData option', () => {
|
test('RFC5424 BuildMessage with structredData option', () => {
|
||||||
const rfc5424 = new SyslogPro.RFC5424();
|
const rfc5424 = new SyslogPro.RFC5424();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user