Commit Graph
9 Commits
Author SHA1 Message Date
Miccah ec1d9a6b4b Refactor log package (#4734)
* Replace logConfig with zapcore.Core

* Add SyncFunc type and tests

* Change Sentry functions to accept a *sentry.Client

This allows the caller to do the error handling.

* Rename newCoreConfig to newCore

* Remove redundant WithCore option

* Update doc comments
2026-02-20 11:03:16 -08:00
Cody Rose 7635b24fd5 Allow logging of caller info (#4731)
This commit extends our logging wrapper code to allow the addition of automatically generated caller information to log entries. It also adds a way to selectively suppress this caller information for individual sinks. This commit does not change any of trufflehog's behavior - it just enables future functionality in case we want it to use it later.

This commit also provides an exportable type alias for sink configuration option functions so that callers have more flexibility in how they prepare groups of them.

This commit also adds some new tests for the existing redactionCore and fixes an existing bug in it. (The bug hasn't yet caused problems, but it created the potential for future problems.)
2026-02-05 17:01:09 -05:00
Cody Rose 8d144c2ba3 Create way to add key-value pairs to new sinks (#4582)
Counterintuitively, a new sink added to an existing logger will not inherit the existing logger's key-value pairs. This has only caused a problem in practice with respect to a small number of known key-value pairs, so this PR creates a way to add specific key-value pairs to new sinks.

This supersedes #4579.
2025-12-08 10:03:25 -05:00
Miccah fe43c5dba4 Add log.ToLogger and log.ToSlogger helper functions (#3629) 2024-11-19 14:57:08 -08:00
Miccah 1018e0095f Remove unused findLevel function (#3628) 2024-11-19 14:01:45 -08:00
Cody Rose f42f63271b Create global log redaction capability (#3522)
Some source use client libraries that can emit errors that contain sensitive information - in particular, git-facing libraries that embed tokens into repository URLs. This PR introduces a way of redacting them - starting with GitLab (where we've seen this most recently), but in theory extensible to other sources as needed.

This implementation uses a custom zap core; this might also be possible with a custom zap encoder, but I didn't test it out.

(The deleted core.go file was entirely unused.)
2024-10-29 09:44:07 -04:00
Cody Rose 4cc10d3da1 delete unused code (#3504) 2024-10-24 10:59:30 -05:00
Miccah f3367d7910 [THOG-643] Implement independent log level controls (#733)
* [THOG-643] Implement independent log level controls

There are two log level controls to mentally distinguish. Log levels
associated with a sink (e.g. stdout and streamed), and log levels
associated with a logger (e.g. a GitHub source).

The level is determined to be the minimum of the two. If a sink is at
level 0, then it will only output level 0 logs regardless of the
logger's level. This is best demonstrated by TestSinkWithName.

* Rename WithName to WithNamedLevel

* Check flush errors

* Replace IncreaseLevelCore with custom LevelCore

Adding a leveler that was less verbose would cause the initialization
fail, and therefore not be added to the core. This check is only at
the time of initialization.

An alternative approach to creating our own core is to set the child log
level equal to the parent, so initialization is guaranteed (with the
added benefit of intuitive behavior).

* Use controller if it exists, otherwise inherit parent's log level

* Cleanup some tests
2022-08-26 15:27:09 -05:00
Miccah 619ab2027a Move context and log libraries to trufflehog (#718)
* Move context and log libraries to trufflehog

* Fix lint errors
2022-08-17 15:03:35 -05:00