Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Jan 18, 2025
1 parent 9192a77 commit 3ad0dad
Show file tree
Hide file tree
Showing 26 changed files with 984 additions and 287 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Automatically create GitHub issues from your Laravel exceptions & logs. Perfect
- 🏷️ Support customizable labels
- 🎯 Smart deduplication to prevent issue spam
- ⚡️ Buffered logging for better performance
- 📝 Customizable issue templates

## Showcase

Expand Down Expand Up @@ -103,7 +104,29 @@ Log::stack(['daily', 'github'])->error('Something went wrong!');

## Advanced Configuration

Deduplication and buffering are enabled by default to enhance logging. Customize these features to suit your needs.
### Customizing Templates

The package uses Markdown templates to format issues and comments. You can customize these templates by publishing them:

```bash
php artisan vendor:publish --tag="github-monolog-views"
```

This will copy the templates to `resources/views/vendor/github-monolog/` where you can modify them:

- `issue.md`: Template for new issues
- `comment.md`: Template for comments on existing issues
- `previous_exception.md`: Template for previous exceptions in the chain

Available template variables:
- `{level}`: Log level (error, warning, etc.)
- `{message}`: The error message or log content
- `{simplified_stack_trace}`: A cleaned up stack trace
- `{full_stack_trace}`: The complete stack trace
- `{previous_exceptions}`: Details of any previous exceptions
- `{context}`: Additional context data
- `{extra}`: Extra log data
- `{signature}`: Internal signature used for deduplication

### Deduplication

Expand Down
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
"phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
"providers": [
"Naoray\\LaravelGithubMonolog\\GithubMonologServiceProvider"
]
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
28 changes: 28 additions & 0 deletions resources/views/comment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# New Occurrence

**Log Level:** {level}

{message}

**Simplified Stack Trace:**
```php
{simplified_stack_trace}
```

<details>
<summary>Complete Stack Trace</summary>

```php
{full_stack_trace}
```
</details>

<details>
<summary>Previous Exceptions</summary>

{previous_exceptions}
</details>

{context}

{extra}
28 changes: 28 additions & 0 deletions resources/views/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
**Log Level:** {level}

{message}

**Simplified Stack Trace:**
```php
{simplified_stack_trace}
```

<details>
<summary>Complete Stack Trace</summary>

```php
{full_stack_trace}
```
</details>

<details>
<summary>Previous Exceptions</summary>

{previous_exceptions}
</details>

{context}

{extra}

<!-- Signature: {signature} -->
15 changes: 15 additions & 0 deletions resources/views/previous_exception.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### Previous Exception #{count}
**Type:** {type}

**Simplified Stack Trace:**
```php
{simplified_stack_trace}
```

<details>
<summary>Complete Stack Trace</summary>

```php
{full_stack_trace}
```
</details>
8 changes: 6 additions & 2 deletions src/GithubIssueHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
use Naoray\LaravelGithubMonolog\Deduplication\DeduplicationHandler;
use Naoray\LaravelGithubMonolog\Deduplication\DefaultSignatureGenerator;
use Naoray\LaravelGithubMonolog\Deduplication\SignatureGeneratorInterface;
use Naoray\LaravelGithubMonolog\Issues\Formatter;
use Naoray\LaravelGithubMonolog\Issues\Formatters\IssueFormatter;
use Naoray\LaravelGithubMonolog\Issues\Handler;

class GithubIssueHandlerFactory
{
public function __construct(
private readonly IssueFormatter $formatter,
) {}

public function __invoke(array $config): Logger
{
$this->validateConfig($config);
Expand Down Expand Up @@ -45,7 +49,7 @@ protected function createBaseHandler(array $config): Handler
bubble: Arr::get($config, 'bubble', true)
);

$handler->setFormatter(new Formatter);
$handler->setFormatter($this->formatter);

return $handler;
}
Expand Down
46 changes: 46 additions & 0 deletions src/GithubMonologServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Naoray\LaravelGithubMonolog;

use Illuminate\Support\ServiceProvider;
use Naoray\LaravelGithubMonolog\Issues\Formatters\ExceptionFormatter;
use Naoray\LaravelGithubMonolog\Issues\Formatters\IssueFormatter;
use Naoray\LaravelGithubMonolog\Issues\Formatters\StackTraceFormatter;
use Naoray\LaravelGithubMonolog\Issues\StubLoader;
use Naoray\LaravelGithubMonolog\Issues\TemplateRenderer;

class GithubMonologServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->bind(StackTraceFormatter::class);
$this->app->bind(StubLoader::class);
$this->app->bind(ExceptionFormatter::class, function ($app) {
return new ExceptionFormatter(
stackTraceFormatter: $app->make(StackTraceFormatter::class),
);
});

$this->app->singleton(TemplateRenderer::class, function ($app) {
return new TemplateRenderer(
exceptionFormatter: $app->make(ExceptionFormatter::class),
stubLoader: $app->make(StubLoader::class),
);
});

$this->app->singleton(IssueFormatter::class, function ($app) {
return new IssueFormatter(
templateRenderer: $app->make(TemplateRenderer::class),
);
});
}

public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__ . '/../resources/views' => resource_path('views/vendor/github-monolog'),
], 'github-monolog-views');
}
}
}
Loading

0 comments on commit 3ad0dad

Please sign in to comment.