Skip to content

Commit bbe4224

Browse files
Replace WithLoggingHandler with WithLogger
1 parent 34384b8 commit bbe4224

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ func (s *MyService) Close() error {
7979

8080
func main() {
8181
// Setup logger
82-
logHandler := slog.NewTextHandler(os.Stdout, nil)
82+
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
8383

8484
// Configure the manager
8585
manager := unixcycle.NewManager(
86-
unixcycle.WithLoggingHandler(logHandler),
86+
unixcycle.WithLogger(logger),
8787
unixcycle.WithSetupTimeout(1*time.Second),
8888
unixcycle.WithCloseTimeout(2*time.Second),
8989
// unixcycle.WithLifetime(unixcycle.InterruptSignal), // Default
@@ -149,7 +149,7 @@ These simplify creating `Component` values:
149149

150150
Pass these to `NewManager` using the `With...` functions:
151151

152-
* `unixcycle.WithLoggingHandler(handler slog.Handler)`: Sets the `slog` handler for logging. If `nil`, logging is disabled (sent to `io.Discard`). Defaults to a text handler writing to `os.Stdout`.
152+
* `unixcycle.WithLogger(logger *slog.Logger)`: Sets the `slog` logger for logging. If `nil`, logging is disabled (sent to `io.Discard`). Defaults to a text handler writing to `os.Stdout`.
153153
* `unixcycle.WithSetupTimeout(time.Duration)`: Timeout for *each* component's `Setup()` call. Defaults to 5 seconds.
154154
* `unixcycle.WithCloseTimeout(time.Duration)`: Timeout for *each* component's `Close()` call. Defaults to 5 seconds.
155155
* `unixcycle.WithLifetime(unixcycle.TerminationSignal)`: A function `func() syscall.Signal` that blocks until termination is requested. Defaults to `unixcycle.InterruptSignal` (waits for `SIGINT` or `SIGTERM`).

options.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package unixcycle
22

33
import (
4-
"io"
54
"log/slog"
65
"time"
76
)
@@ -39,16 +38,11 @@ func WithCloseTimeout(timeout time.Duration) managerOption {
3938
}
4039
}
4140

42-
// WithLoggingHandler sets the logger for the manager
41+
// WithLogger sets the logger for the manager
4342
// If handler is nil, the manager will log nothing
4443
// Default is a text logging handler that writes to os.Stdout
45-
func WithLoggingHandler(handler slog.Handler) managerOption {
44+
func WithLogger(logger *slog.Logger) managerOption {
4645
return func(o *managerOptions) {
47-
if handler == nil {
48-
o.logger = slog.New(slog.NewTextHandler(io.Discard, nil))
49-
return
50-
}
51-
52-
o.logger = slog.New(handler)
46+
o.logger = logger
5347
}
5448
}

resign_commits.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
# Script to re-sign all commits in the repository with your current GPG key
4+
# This will rewrite commit history, so use with caution
5+
6+
set -e
7+
8+
echo "=== Git Commit Re-signing Script ==="
9+
echo "This will rewrite ALL commit history to be authored by you with GPG signatures."
10+
echo "Current GPG signing key: $(git config user.signingkey)"
11+
echo "Current user: $(git config user.name) <$(git config user.email)>"
12+
echo ""
13+
14+
# Check if GPG signing is enabled
15+
if [[ "$(git config commit.gpgsign)" != "true" ]]; then
16+
echo "❌ GPG signing is not enabled. Please run: git config commit.gpgsign true"
17+
exit 1
18+
fi
19+
20+
# Check if we have a signing key configured
21+
if [[ -z "$(git config user.signingkey)" ]]; then
22+
echo "❌ No GPG signing key configured. Please run: git config user.signingkey YOUR_KEY_ID"
23+
exit 1
24+
fi
25+
26+
echo "Creating backup branch..."
27+
BACKUP_BRANCH="backup-before-resign-$(date +%Y%m%d-%H%M%S)"
28+
git checkout -b "$BACKUP_BRANCH"
29+
git checkout master
30+
31+
echo "Starting commit history rewrite..."
32+
echo "This may take a while depending on the number of commits..."
33+
34+
# Set up GPG environment for non-interactive signing
35+
export GPG_TTY=$(tty)
36+
export FILTER_BRANCH_SQUELCH_WARNING=1
37+
38+
# Test GPG signing first
39+
echo "Testing GPG signing..."
40+
if ! echo "test" | gpg --batch --yes --default-key "$(git config user.signingkey)" --detach-sign > /dev/null 2>&1; then
41+
echo "❌ GPG signing test failed. You may need to enter your passphrase."
42+
echo "Trying interactive GPG test..."
43+
if ! echo "test" | gpg --default-key "$(git config user.signingkey)" --detach-sign > /dev/null; then
44+
echo "❌ GPG signing failed. Please check your GPG setup."
45+
exit 1
46+
fi
47+
fi
48+
echo "✅ GPG signing test passed"
49+
50+
# Use git filter-branch to rewrite ALL commits as you with signatures
51+
git filter-branch -f --env-filter '
52+
export GIT_AUTHOR_NAME="'"$(git config user.name)"'"
53+
export GIT_AUTHOR_EMAIL="'"$(git config user.email)"'"
54+
export GIT_COMMITTER_NAME="'"$(git config user.name)"'"
55+
export GIT_COMMITTER_EMAIL="'"$(git config user.email)"'"
56+
export GPG_TTY=$(tty)
57+
' --commit-filter '
58+
git commit-tree -S "$@"
59+
' HEAD
60+
61+
echo ""
62+
echo "✅ Commit history rewrite complete!"
63+
echo "🔒 All commits are now authored by you and signed with your current GPG key"
64+
echo "📦 Backup created in branch: $BACKUP_BRANCH"
65+
echo ""
66+
echo "Next steps:"
67+
echo "1. Verify the signatures: git log --show-signature"
68+
echo "2. If everything looks good, you can delete the backup: git branch -D $BACKUP_BRANCH"
69+
echo "3. Force push to update remote: git push --force-with-lease origin master"
70+
echo ""
71+
echo "⚠️ WARNING: This has rewritten commit history and changed all commit authorship."
72+
echo " All commits now appear to be authored by you with your GPG signature."

0 commit comments

Comments
 (0)