Skip to content

Commit 5dffe01

Browse files
authored
Merge pull request #19 from mki98/patch-1
Suggest fix for incomaptiabilty with windows file system
2 parents e166985 + 1fb7551 commit 5dffe01

17 files changed

+9
-9
lines changed

chapters/ch04.2-writing-logs.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class Logger {
410410
#log_file_handle;
411411

412412
async init() {
413-
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/\..+/, "") + ".log";
413+
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/[\.:]+/, "-") + ".log";
414414
this.#log_file_handle = await fs.open(file_name, "a+");
415415
}
416416
}
@@ -467,7 +467,7 @@ class Logger {
467467
...
468468

469469
async init() {
470-
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/\..+/, "") + ".log";
470+
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/[\.:]+/, "-") + ".log";
471471
this.#log_file_handle = await fs.open(file_name, "a+");
472472
console.log("File created.")
473473
}
@@ -602,7 +602,7 @@ Update the code inside `Logger.init` method:
602602
const path = require('node:path')
603603

604604
async init() {
605-
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/\..+/, "") + ".log";
605+
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/[\.:]+/, "-") + ".log";
606606
this.#log_file_handle = await fs.open(path.join('logs', file_name), "a+");
607607
}
608608
```
@@ -699,7 +699,7 @@ Let's go through the `check_and_create_dir` function's code line by line.
699699
async init() {
700700
const log_dir_path = check_and_create_dir("logs")
701701

702-
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/\..+/, "") + ".log";
702+
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/[\.:]+/, "-") + ".log";
703703

704704
// Open/Create the file at the specified log directory and
705705
// save the file handle to the `#log_file_handle` for further
@@ -793,4 +793,4 @@ We'll take care of all this in the next chapter.
793793
794794
[![Read Next](/assets/imgs/next.png)](/chapters/ch04.3-capturing-metadata.md)
795795

796-
![](https://uddrapi.com/api/img?page=ch04.2)
796+
![](https://uddrapi.com/api/img?page=ch04.2)

chapters/ch04.5-rolling-file-support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ We call the `Logger.init` method to create the new file again. Here's the code f
155155
async init() {
156156
const log_dir_path = check_and_create_dir("logs");
157157

158-
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/\..+/, "") + ".log";
158+
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/[\.:]+/, "-") + ".log";
159159
    this.#log_file_handle = await fs.open(path.join(log_dir_path, file_name), "a+");
160160
}
161161
```

code/chapter_04.2/lib/logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Logger {
2828
async init() {
2929
const log_dir_path = check_and_create_dir("logs")
3030

31-
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/\..+/, "") + ".log";
31+
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/[\.:]+/, "-") + ".log";
3232
this.#log_file_handle = await fs.open(path.join(log_dir_path, file_name), "a+");
3333
}
3434

File renamed without changes.

code/chapter_04.3/lib/logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Logger {
4444
async init() {
4545
const log_dir_path = check_and_create_dir("logs");
4646

47-
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/\..+/, "") + ".log";
47+
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/[\.:]+/, "-") + ".log";
4848
this.#log_file_handle = await fs.open(path.join(log_dir_path, file_name), "a+");
4949
}
5050

File renamed without changes.

code/chapter_04.5/lib/logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Logger {
3232
async init() {
3333
const log_dir_path = check_and_create_dir("logs");
3434

35-
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/\..+/, "") + ".log";
35+
const file_name = this.#config.file_prefix + new Date().toISOString().replace(/[\.:]+/, "-") + ".log";
3636
this.#log_file_handle = await fs.open(path.join(log_dir_path, file_name), "a+");
3737
}
3838

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)