-
Notifications
You must be signed in to change notification settings - Fork 16
feat: session based logs with date hierarchy #2242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
naman-contentstack
wants to merge
12
commits into
development
Choose a base branch
from
feat/DX-3646
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3ce1ba2
feat: session based logs with date hierarchy
192ba55
resolved comments
349f207
feat: add v2 logger in clone
e35c2e9
updated debug logs
9c0c100
Merge branch 'feat/DX-3646' into feat/DX-3700
fac8313
updated talisman
42828b5
resolved comments
570714c
Merge branch 'development' into feat/DX-3646
6d46d49
updated package-lock
6918642
Merge branch 'feat/DX-3646' into feat/DX-3700
f003dba
resolved comments
077cd8f
Merge pull request #2244 from contentstack/feat/DX-3700
naman-contentstack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
packages/contentstack-utilities/src/logger/session-path.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import * as fs from 'fs'; | ||
| import * as os from 'os'; | ||
| import * as path from 'path'; | ||
| import * as shortUUID from 'short-uuid'; | ||
| import { configHandler } from '..'; | ||
|
|
||
| /** | ||
| * Get the log path for centralized logging | ||
| * Priority: | ||
| * 1. CS_CLI_LOG_PATH environment variable (user override) | ||
| * 2. User config (log.path from CLI config) | ||
| * 3. Current working directory + logs (where user ran the command) | ||
| * 4. Home directory (~/contentstack/logs) (fallback) | ||
| */ | ||
| function getLogPath(): string { | ||
| // 1. Environment variable override | ||
| if (process.env.CS_CLI_LOG_PATH) { | ||
| return process.env.CS_CLI_LOG_PATH; | ||
| } | ||
|
|
||
| // 2. User configured path | ||
| const configuredPath = configHandler.get('log.path'); | ||
| if (configuredPath) { | ||
| return configuredPath; | ||
| } | ||
|
|
||
| // 3. Use current working directory (where user ran the command) | ||
| try { | ||
| const cwdPath = path.join(process.cwd(), 'logs'); | ||
| if (!fs.existsSync(cwdPath)) { | ||
| fs.mkdirSync(cwdPath, { recursive: true }); | ||
| } | ||
| fs.accessSync(cwdPath, fs.constants.W_OK); | ||
| return cwdPath; | ||
| } catch (error) { | ||
| // If current directory is not writable, fall back to home directory | ||
| } | ||
|
|
||
| // 4. Fallback to home directory | ||
| return path.join(os.homedir(), 'contentstack', 'logs'); | ||
| } | ||
|
|
||
| /** | ||
| * Get the session-based log path for date-organized logging | ||
| * Structure: {basePath}/{YYYY-MM-DD}/{command}-{YYYYMMDD-HHMMSS}-{sessionId}/ | ||
| * | ||
| * @returns The session-specific log directory path | ||
| */ | ||
| export function getSessionLogPath(): string { | ||
| // Get base log path | ||
| const basePath = getLogPath(); | ||
|
|
||
| // Get current date in YYYY-MM-DD format | ||
| const now = new Date(); | ||
| const dateStr = now.toISOString().split('T')[0]; // YYYY-MM-DD | ||
|
|
||
| // Get command ID (fallback to 'unknown' if not set) | ||
| let commandId = configHandler.get('currentCommandId') || 'unknown'; | ||
| // Sanitize command ID - remove colons and replace with hyphens for folder name | ||
| commandId = commandId.replace(/:/g, '-'); | ||
naman-contentstack marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Get sessionId (fallback to short UUID if not set) | ||
| let sessionId = configHandler.get('sessionId'); | ||
| if (!sessionId) { | ||
| sessionId = shortUUID.generate(); | ||
naman-contentstack marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| configHandler.set('sessionId', sessionId); | ||
| } | ||
|
|
||
| // Get timestamp in YYYYMMDD-HHMMSS format | ||
| const year = now.getFullYear(); | ||
| const month = String(now.getMonth() + 1).padStart(2, '0'); | ||
| const day = String(now.getDate()).padStart(2, '0'); | ||
| const hours = String(now.getHours()).padStart(2, '0'); | ||
| const minutes = String(now.getMinutes()).padStart(2, '0'); | ||
| const seconds = String(now.getSeconds()).padStart(2, '0'); | ||
| const timestamp = `${year}${month}${day}-${hours}${minutes}${seconds}`; | ||
naman-contentstack marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Create session folder name: command-YYYYMMDD-HHMMSS-sessionId | ||
| const sessionFolderName = `${commandId}-${timestamp}-${sessionId}`; | ||
|
|
||
| // Build full session path | ||
| const sessionPath = path.join(basePath, dateStr, sessionFolderName); | ||
|
|
||
| // Ensure directory exists | ||
| if (!fs.existsSync(sessionPath)) { | ||
| fs.mkdirSync(sessionPath, { recursive: true }); | ||
| } | ||
|
|
||
| return sessionPath; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.