Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chapters/ch04.2-writing-logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ class Logger {
}

// write logs to the opened file
await this.#log_file_handle.write(log_message);
await this.#log_file_handle.write(message);
}
...
}
Expand Down
22 changes: 11 additions & 11 deletions chapters/ch04.5-rolling-file-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const current_time = new Date().getTime();
We are creating a new `Date` object and uses the `getTime()` method to obtain the current time in milliseconds since epoch.

```js
if (size >= size_threshold || (current_time - birthtimeMs >= time_threshold)) {
if (size >= size_threshold || (current_time - birthtimeMs >= time_threshold * 1000)) {
```

We'll be creating a new file:
Expand Down Expand Up @@ -478,19 +478,19 @@ Run the `test.js` script. You'll notice a new file created every now and then. L
```bash
$ ls -al ./logs

.rw-r--r-- 10k ishtmeet 22 Aug 06:11 Logtar_2023-08-22T00-41-58-132Z.log
.rw-r--r-- 10k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-41-59-232Z.log
.rw-r--r-- 10k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-01-101Z.log
.rw-r--r-- 10k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-02-139Z.log
.rw-r--r-- 10k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-03-545Z.log
.rw-r--r-- 10k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-04-132Z.log
.rw-r--r-- 10k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-05-382Z.log
.rw-r--r-- 10k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-06-432Z.log
.rw-r--r-- 10k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-07-109Z.log
.rw-r--r-- 20k ishtmeet 22 Aug 06:11 Logtar_2023-08-22T00-41-58-132Z.log
.rw-r--r-- 20k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-41-59-232Z.log
.rw-r--r-- 20k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-01-101Z.log
.rw-r--r-- 20k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-02-139Z.log
.rw-r--r-- 20k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-03-545Z.log
.rw-r--r-- 20k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-04-132Z.log
.rw-r--r-- 20k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-05-382Z.log
.rw-r--r-- 20k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-06-432Z.log
.rw-r--r-- 20k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-07-109Z.log
.rw-r--r-- 3.6k ishtmeet 22 Aug 06:12 Logtar_2023-08-22T00-42-08-138Z.log
```

Each file is only 10KB, which is exactly what we need. However, the last file is not 10KB because I had to exit the infinite loop caused by `setInterval` by pressing `Ctrl + C`.
Each file is only 20KB, which is exactly what we need. However, the last file is not 20KB because I had to exit the infinite loop caused by `setInterval` by pressing `Ctrl + C`.

We now have an actual logging library that can be used with any type of project. However, there is still something we need to take care of: providing a middleware function that can be used.

Expand Down