Skip to content

Commit d73ddaf

Browse files
authored
Merge pull request #16 from OpenForgeProject/feature/timestamp
feat: add timestamp formatting for log entries
2 parents 57256c3 + 276c087 commit d73ddaf

File tree

3 files changed

+82
-24
lines changed

3 files changed

+82
-24
lines changed

CHANGELOG.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,101 +2,108 @@
22

33
All notable changes to the "magento-log-viewer" extension will be documented in this file.
44

5+
6+
## Next release
7+
8+
- feat: improved timestamp formatting for log entries
9+
10+
---
11+
512
## Latest Release
613

7-
## [1.10.2] - 2025-05-28
14+
### [1.10.2] - 2025-05-28
815
- update: `readme.md` update
916
- fix: update notification for better performance
1017
- fix: update configuration keys for Magento project selection to correctly save "Is this a Magento project" response
1118

12-
## [1.10.1] - 2025-03-12
19+
### [1.10.1] - 2025-03-12
1320

1421
- fix: update notification message
1522

16-
## [1.10.0] - 2025-03-12
23+
### [1.10.0] - 2025-03-12
1724

1825
- feat: add update notification for new extension version
1926

20-
## [1.9.0] - 2025-03-12
27+
### [1.9.0] - 2025-03-12
2128

2229
- feat: add color coding for log levels in log viewer
2330
- fix: project configuration handling and cleanup process for a smoother experience when opening or closing Magento projects.
2431

25-
## [1.8.2] - 2025-01-20
32+
### [1.8.2] - 2025-01-20
2633

2734
- add: conditional display of "Is this a Magento Project?" message only when project or workspace is loaded
2835

29-
## [1.8.1] - 2024-12-26
36+
### [1.8.1] - 2024-12-26
3037

3138
- add: Sponsor Link
3239
- add: Install-Counter in `Readme.md`
3340

34-
## [1.8.0] - 2024-12-25
41+
### [1.8.0] - 2024-12-25
3542

3643
- add: collapsed reports added if error titles are identical
3744
- fix: Removed not used "Hello World" command
3845
- update: Change Logo for Marketplace
3946

40-
## [1.7.1] - 2024-12-09
47+
### [1.7.1] - 2024-12-09
4148

4249
- add: a message when there are no report files.
4350
- add: Support for Node.js 18.x in GitHub Actions
4451
- add: Automated tests for releases using GitHub Workflows
4552
- fix: an issue where the status bar item was being created multiple times.
4653

47-
## [1.7.0] - 2024-12-08
54+
### [1.7.0] - 2024-12-08
4855

4956
- add: a right click context menu to delete report files
5057
- add: tests to check the extension features automaticly
5158
- update: `README.md` with latest features
5259
- update: Extension Logo
5360
- update: Changelog Dates for 1.6.0 Release Date
5461

55-
## [1.6.0] - 2024-12-07
62+
### [1.6.0] - 2024-12-07
5663

5764
- add: icons for different report types based on content.
5865
- add: folder names in titles for files in the "api" subdirectory.
5966
- update: report file titles by parsing content for better readability.
6067
- update: refactor code to improve performance
6168
- fix: extend badge counter to include report files
6269
- fix: fixed issue with empty directories being included in the report list.
63-
## [1.5.1] - 2024-12-05
70+
### [1.5.1] - 2024-12-05
6471

6572
- fix: issue that caused the Reload button to not display any results
6673

67-
## [1.5.0] - 2024-12-04
74+
### [1.5.0] - 2024-12-04
6875

6976
- add: sort log entries and message groups alphabetically
7077

71-
## [1.4.0] - 2024-11-20
78+
### [1.4.0] - 2024-11-20
7279

7380
- add: confirmation popup to ask if you really want to delete all files
7481
- fix: "Delete Logfiles" button visibility based on log file presence
7582
- update: Refactored the Extension to improve readability, performance and maintainability
7683

77-
## [1.3.0] - 2024-11-19
84+
### [1.3.0] - 2024-11-19
7885

7986
- add: Workspace configuration option to group log entries by message content
8087
- add: Video to `README.md`
8188
- add: Setting to group Logfile Messages with counter display "grouped" (e.g., `INFO (128, grouped)`)
8289

83-
## [1.2.2] - 2024-11-19
90+
### [1.2.2] - 2024-11-19
8491

8592
- fix: code duplication by extracting logic into functions for improved Extension Performance
8693
- fix: trailing comma in `tsconfig.json`
8794

88-
## [1.2.1] - 2024-11-19
95+
### [1.2.1] - 2024-11-19
8996

9097
- add: Codacy Code Quality Badge to `README.md`
9198
- fix: TypeScript ES2022 issues
9299

93-
## [1.2.0] - 2024-11-17
100+
### [1.2.0] - 2024-11-17
94101

95102
- add: Comprehensive bug report template
96103
- add: Detailed feature request template
97104
- update: Settings now saved in workspace instead of globally in USER
98105

99-
## [1.1.0] - 2024-11-16
106+
### [1.1.0] - 2024-11-16
100107

101108
- Improved the user interface of the webview panel.
102109
- add: line number formatting with leading zeros.
@@ -105,17 +112,17 @@ All notable changes to the "magento-log-viewer" extension will be documented in
105112
- Fixed potential security issue with non-literal argument in `fs.existsSync`.
106113
- Fixed potential object injection issue in `groupLogEntries` method.
107114

108-
## [1.0.2] - 2024-10-10
115+
### [1.0.2] - 2024-10-10
109116

110117
- Repository URL to `https://github.com/OpenForgeProject/vscode-ext-magento-log-viewer`
111118

112-
## [v1.0.1]
119+
### [v1.0.1]
113120

114121
- Extension Logo
115122
- Screenshot in the README file.
116123
- add: a "Getting Started" section to the README.
117124

118-
## [v1.0.0]
125+
### [v1.0.0]
119126

120127
- View log files in the `var/log` directory of your Magento project.
121128
- Open log files directly in the editor by clicking on them in the tree view.

src/helpers.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,50 @@ export function getReportItems(dir: string): LogItem[] {
326326

327327
return items;
328328
}
329+
330+
// Formats a timestamp from ISO format to localized user format
331+
export function formatTimestamp(timestamp: string): string {
332+
try {
333+
// Look for Magento log timestamp pattern: [2025-05-27T19:42:17.646000+00:00]
334+
// First check for the exact format seen in the logs
335+
// Using a more relaxed regex that will match the format in the screenshot
336+
const regex = /(\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+\+\d{2}:\d{2}\])/;
337+
const match = timestamp.match(regex);
338+
339+
if (!match || !match[1]) {
340+
return timestamp; // Return original if no timestamp format matches
341+
}
342+
343+
// Extract the timestamp without brackets
344+
const dateTimeStr = match[1].substring(1, match[1].length - 1);
345+
346+
try {
347+
const date = new Date(dateTimeStr);
348+
349+
// Check if date is valid
350+
if (isNaN(date.getTime())) {
351+
return timestamp; // Return original if date parsing failed
352+
}
353+
354+
// Format the date according to user's locale
355+
const localizedTimestamp = date.toLocaleString(undefined, {
356+
year: 'numeric',
357+
month: '2-digit',
358+
day: '2-digit',
359+
hour: '2-digit',
360+
minute: '2-digit',
361+
second: '2-digit',
362+
hour12: false
363+
});
364+
365+
// Replace the ISO timestamp with the localized one
366+
return timestamp.replace(match[1], `[${localizedTimestamp}]`);
367+
} catch (parseError) {
368+
console.error("Error parsing date:", parseError);
369+
return timestamp; // Return original on date parsing error
370+
}
371+
} catch (error) {
372+
console.error('Failed to format timestamp:', error instanceof Error ? error.message : String(error));
373+
return timestamp; // Return original on error
374+
}
375+
}

src/logViewer.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode';
22
import * as fs from 'fs';
33
import * as path from 'path';
4-
import { pathExists, getLineCount, getIconForLogLevel, getLogItems, parseReportTitle, getIconForReport } from './helpers';
4+
import { pathExists, getLineCount, getIconForLogLevel, getLogItems, parseReportTitle, getIconForReport, formatTimestamp } from './helpers';
55

66
export class LogViewerProvider implements vscode.TreeDataProvider<LogItem>, vscode.Disposable {
77
private _onDidChangeTreeData: vscode.EventEmitter<LogItem | undefined | void> = new vscode.EventEmitter<LogItem | undefined | void>();
@@ -127,8 +127,10 @@ export class LogViewerProvider implements vscode.TreeDataProvider<LogItem>, vsco
127127
return new LogItem(label, vscode.TreeItemCollapsibleState.Collapsed, undefined,
128128
messageEntries.map(entry => {
129129
const lineNumber = (entry.lineNumber + 1).toString().padStart(2, '0');
130+
// Format the timestamp in the log entry
131+
const formattedLine = formatTimestamp(entry.line);
130132
return new LogItem(
131-
`Line ${lineNumber}: ${entry.line}`,
133+
`Line ${lineNumber}: ${formattedLine}`,
132134
vscode.TreeItemCollapsibleState.None,
133135
{
134136
command: 'magento-log-viewer.openFileAtLine',
@@ -147,8 +149,10 @@ export class LogViewerProvider implements vscode.TreeDataProvider<LogItem>, vsco
147149
const logFile = new LogItem(`${level} (${entries.length})`, vscode.TreeItemCollapsibleState.Collapsed, undefined,
148150
entries.map(entry => {
149151
const lineNumber = (entry.lineNumber + 1).toString().padStart(2, '0');
152+
// Format the timestamp in the log entry
153+
const formattedLine = formatTimestamp(entry.line);
150154
return new LogItem(
151-
`Line ${lineNumber}: ${entry.line}`,
155+
`Line ${lineNumber}: ${formattedLine}`,
152156
vscode.TreeItemCollapsibleState.None,
153157
{
154158
command: 'magento-log-viewer.openFileAtLine',

0 commit comments

Comments
 (0)