Edvard
e947e03ed2
🔥 feat(logger): Add predefined log formats ( #3359 )
...
* feat(logger): Add predefined log formats
This commit introduces predefined log formats for the logger middleware, enhancing its flexibility and ease of use. Users can now specify formats like "common", "combined", and "json" in addition to the default format.
Changes:
- Added a `format.go` file to store predefined log format constants.
- Updated `config.go` to include documentation for the `Format` configuration option, explaining the available placeholders and predefined formats.
- Modified `logger.go` to utilize the predefined formats based on the `Format` configuration.
- Added a new test case `Test_Logger_CLF` in `logger_test.go` to verify the "common" log format.
* feat(logger): Use predefined formats and fix default format
This commit updates the logger middleware to utilize the predefined log formats introduced in a previous commit. It also fixes the default format to use the `FormatDefault` constant.
Changes:
- Updated `config.go` to use `FormatDefault` constant for the default format.
- Updated `default_logger.go` to use `FormatDefault` constant for the default format.
- Added new test cases in `logger_test.go` to verify the "common", "combined" and "json" log formats.
- Updated `format.go` to add newline character to the end of the default format.
* feat(logger): Document and exemplify predefined formats
* fix(logger): Improve test assertions based on golangci-lint
* docs(logger): Improve documentation and formatting logger.md based on markdownlint-cli2
* docs(logger): Improve documentation based on markdownlint-cli2
* fix(logger): Improve combined and JSON format tests
* feat(logger): Add ECS log format
* feat(logger): Add CustomFormat option
This commit introduces a `CustomFormat` option to the `Config` struct, allowing users to specify a predefined format (like "common", "combined", "json", or "ecs")
* feat(logger): Add ECS log format to examples and config
* docs(logger): Update examples in whats_new.md
* feat(logger): Remove CustomFormat option and renamed Format consts
- Removed `CustomFormat` field from `Config`.
- Removed `LoggerConfig` map.
- Rename predefined formats constants.
* docs(logger): Update documentation and examples after format refactor
---------
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-03-21 16:13:21 +01:00
Juan Calderon-Perez
395c8fafa9
🧹 chore: Fix linter workflow failures ( #3354 )
...
* Fix linter workflow failures
* Bump golang.org/x/net to v0.36.0
* Try skipping golangci-lint cache
* Update linter.yml
* fix: directives and spaces
* fix: better configuration
* fix: golangci-lint install
* Update golangci-lint version
* Enable SA4023
* Update golangci-lint config
* Remove duplicated rule
---------
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2025-03-17 08:29:51 +01:00
JIeJaitt
c0599ee1d4
🔥 feat: Add Skip function to logger middleware ( #3333 )
...
* 🔥 Feature(logger): Add Filter option to logger middleware
* 📚 Doc(logger): Clarify Filter middleware description
* 🚨 Test(logger): Enhance logger filter test with parallel subtests
* 🔒 Test(logger): Add mutex to prevent race conditions in logger test
* 🔥 Feature(logger): Add Filter option to logger middleware
* 📚 Doc(logger): Clarify Filter middleware description
* 🚨 Test(logger): Enhance logger filter test with parallel subtests
* 🔒 Test(logger): Add mutex to prevent race conditions in logger test
* 🚨 Test(logger): Refactor logger test to improve test isolation
* Fix issue with unit-tests
* Update middleware/logger/logger_test.go
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* Apply logger filter as soon as possible
* 📚 Doc: Add logger filter configuration example to whats_new.md
* 📚 Doc: Update logger filter documentation in whats_new.md
* 📚 Doc: Update logger filter documentation and examples
* 🩹 Fix: improve what_new.md
* Update logic for Filter() in Logger middleware. Add more unit-tests
* Rename fields to match expressjs/morgan
* Update middleware/logger/default_logger.go
---------
Co-authored-by: Juan Calderon-Perez <jgcalderonperez@protonmail.com>
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: RW <rene@gofiber.io>
2025-03-10 09:06:11 +01:00
Juan Calderon-Perez
dcdd2eb2c6
Bump golangci-lint to v1.62.0 ( #3196 )
2024-11-11 10:37:27 +01:00
Juan Calderon-Perez
a57b3c00c4
🐛 bug: Use Content-Length for bytesReceived and bytesSent tags in Logger Middleware ( #3066 )
...
* logger: Use Content-Length header for BytesReceived and BytesSent tags
* Use strconv.AppendInt instead of fasthttp.AppendUint
2024-07-23 08:35:50 +02:00
Juan Calderon-Perez
46fffe4397
Bump golangci-lint to v1.59.1 ( #3029 )
2024-06-11 08:52:49 +02:00
nickajacks1
82070cb4c8
chore: Update golangci-lint to enable more lint rules ( #2923 )
...
* chore(lint): enable ifElseChange and clean up config a bit
* chore(lint): enable gocritic diagnostic checks
2024-03-18 14:50:40 +01:00
nickajacks1
70067a1754
♻️ Refactor: Remove mutex lock in logger middleware ( #2840 )
...
While not all implementations of io.Write will be goroutine safe, the
vast majority of users of the logger middleware are likely to use
os.File, which does implement safe concurrent writes. If users require
locking, they can implement this on an as-needed basis. The risk of
having global locking is that a slow write can hold up the entire
server.
2024-02-10 03:32:37 +03:00
Nicholas Jackson
059c0e33ed
🎨 Style: Clean up errcheck config
...
Globally ignore several methods that always return nil error.
Disable revive and gosec rules for error checking in favor of errcheck.
2024-02-09 12:23:59 -08:00
Joey
2b03f47fae
🚀 Performance improvements ( #2838 )
...
* Add new supporter
* Add new test condition
* Add Handler Type
* Update app.go
* Update group.go
* Add Handler Type
* Update ViewEngine
* Update Templates Interface
* Update template examples
* Update fasthttp to v1.13.1
* Default cookie SameSite to Lax
* - static file routing fixed for fasthttp 1.13
- fix expected cookie values in tests
* Update template examples
* Update fasthttp to v1.13.1
Co-Authored-By: Thomas van Vugt <thomasvvugt@users.noreply.github.com>
* Cookie SameSite defaults to Lax
Co-Authored-By: Thomas van Vugt <thomasvvugt@users.noreply.github.com>
Co-Authored-By: Queru <pascal@queru.net>
* Fix router bug
Co-Authored-By: RW <renewerner87@googlemail.com>
* Remove unused code
Co-Authored-By: RW <renewerner87@googlemail.com>
* Add more static tests
Co-Authored-By: RW <renewerner87@googlemail.com>
* Update app_test.go
Co-Authored-By: RW <renewerner87@googlemail.com>
* Update Static tests
Co-Authored-By: RW <renewerner87@googlemail.com>
* Update app_test.go
Co-Authored-By: RW <renewerner87@googlemail.com>
* Update app_test.go
Co-Authored-By: RW <renewerner87@googlemail.com>
* Fix handler next calls
Co-Authored-By: RW <renewerner87@googlemail.com>
* Update router.go
Co-Authored-By: RW <renewerner87@googlemail.com>
* Update ctx.go
Co-Authored-By: RW <renewerner87@googlemail.com>
* Update app_test.go
Co-Authored-By: RW <renewerner87@googlemail.com>
* Remove nextHandler
Co-Authored-By: RW <renewerner87@googlemail.com>
* Remove lencount
Co-Authored-By: RW <renewerner87@googlemail.com>
* Add ErrorHandler
* Add ErrorHandler tests
* Add recover by default
* Enable recover by default
* Add App()
* Add ErrorHandler
* Enable recover by default
* Add ErrorHandler
* Add App() & Middleware
* Add RequestID
* Add new supporters
* Update shields
* Add mw
* Update basic_auth.go
* Update README.md
* Update spacing
* Update basic_auth_test.go
* Update ctx_test.go
* Add tests
* Update middleware
* up
* Small improvements
Use optimized `utils.ToString` and avoid `once.Do`
**Before**
```
BenchmarkLogfKeyAndValues/test_logf_with_debug_level_and_key-values-24 7323432 153.8 ns/op 89 B/op 1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_info_level_and_key-values-24 8171703 144.5 ns/op 81 B/op 1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_warn_level_and_key-values-24 8207860 142.8 ns/op 81 B/op 1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_format_and_key-values-24 7500332 159.1 ns/op 135 B/op 2 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_one_key-24 10024760 131.0 ns/op 155 B/op 2 allocs/op
```
**After**
```
BenchmarkLogfKeyAndValues/test_logf_with_debug_level_and_key-values-24 13797813 77.42 ns/op 77 B/op 0 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_info_level_and_key-values-24 15375350 75.43 ns/op 73 B/op 1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_warn_level_and_key-values-24 14926300 75.28 ns/op 75 B/op 1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_format_and_key-values-24 12860275 90.27 ns/op 134 B/op 2 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_one_key-24 15649615 74.98 ns/op 100 B/op 1 allocs/op
```
* Fix WithCtxCaller test
* Fix lint
* Fix lint
* Replace Sprintf with byebufferpool in ctx.String()
# Original fn using Sprintf
Benchmark_Ctx_String-24 3846717 318.0 ns/op 152 B/op 8 allocs/op
Benchmark_Ctx_String-24 3780208 315.9 ns/op 152 B/op 8 allocs/op
Benchmark_Ctx_String-24 3627513 315.1 ns/op 152 B/op 8 allocs/op
Benchmark_Ctx_String-24 3712863 317.4 ns/op 152 B/op 8 allocs/op
// Modified using bytebufferpool
Benchmark_Ctx_String-24 8131666 149.3 ns/op 96 B/op 5 allocs/op
Benchmark_Ctx_String-24 7626406 148.3 ns/op 96 B/op 5 allocs/op
Benchmark_Ctx_String-24 8194621 149.2 ns/op 96 B/op 5 allocs/op
Benchmark_Ctx_String-24 8297750 156.6 ns/op 96 B/op 5 allocs/op
* Fix linting
* Use bytebufferpool in default logger
* Fix linting
* Lint fix
* Update linter.yml
* Update linter.yml
* Disable caching as recommended by golangci-lint
* 🩹 fix lint errors
---------
Co-authored-by: ReneWerner87 <ReneWerner87@googlemail.com>
Co-authored-by: Thomas van Vugt <thomasvvugt@users.noreply.github.com>
Co-authored-by: Queru <pascal@queru.net>
Co-authored-by: ReneWerner87 <rene@gofiber.io>
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2024-02-09 12:27:21 +01:00
nickajacks1
926c537252
fix(logger): print to stderr if log fails for default format ( #2830 )
...
We log to stderr if logging fails when a custom format is used, but not
for the default format. This change addresses this inconsistency.
2024-02-05 08:16:34 +01:00
Muhammed Efe Cetin
6ea4d81331
Merge branch 'master' into v3-beta
2023-11-07 20:22:31 +03:00
Muhammed Efe Cetin
44acb06c02
🧹 v3 (chore): fix linter warnings
2023-08-05 22:25:21 +03:00
Muhammed Efe Cetin
75bb02b87e
Merge remote-tracking branch 'origin/master' into v3-beta
2023-08-05 22:02:01 +03:00
Muhammed Efe Çetin
c2749c36c2
👷 v3 (ci): fix some linter warnings
2023-02-09 22:33:45 +03:00
Muhammed Efe Çetin
088cde594d
Merge remote-tracking branch 'origin/master' into v3-beta
2023-02-05 23:43:42 +03:00
Muhammed Efe Çetin
c62dd16e8d
Merge remote-tracking branch 'origin/master' into v3-beta
2022-11-27 20:34:48 +03:00
M. Efe Çetin
e9db6c70d2
v3: fix logger benchmarks ( #2074 )
...
* v3: fix logger benchmarks
* fix datarace
* fix datarace
* fix datarace
2022-09-06 17:54:39 +02:00
Muhammed Efe Çetin
e3282f6408
♻️ v3 (enhancement): replace `c.Hostname()` -> `c.Host()` & add `c.Hostname()` that returns host without port
2022-09-06 18:43:06 +03:00
M. Efe Çetin
154e4f8201
✨ v3 (feature): refactor logger middleware ( #1979 )
...
* ✨ v3 (feature): refactor logger middleware
- Make middleware extandable for 3rd-party loggers. (https://github.com/gofiber/fiber/issues/1828 )
* ✨ v3 (feature): refactor logger middleware
- Make middleware extandable for 3rd-party loggers. (https://github.com/gofiber/fiber/issues/1828 )
* ✨ v3 (feature): refactor logger middleware
- add example for zerolog.
* ✨ v3 (feature): refactor logger middleware
- fix ToC.
* merge
2022-09-05 13:15:42 +02:00