-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
800 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Konfiguracja programu | ||
|
||
W chwili obecnej jedyne co można skonfigurować to poziom loggerów, ale nie wykluczam, że w przyszłości pojawią się kolejne opcje. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Diagnostyka / Logowanie | ||
|
||
Aby ułatwić diagnozowanie problemów z programem, przewidziałem logowanie na kilku poziomach. Oznacza to, że możesz włączyć loggery selektywnie, w zależności od tego gdzie program się wywala / działa w sposób niepożądany. | ||
|
||
## Jak włączyć logowanie | ||
|
||
Stwórz plik konfiguracyjny z poniższą składnią | ||
|
||
```yaml | ||
logging: | ||
nazwa-loggera: poziom | ||
``` | ||
dostępne poziomy: `info`, `debug`, `error` | ||
|
||
A następnie wywołaj program z przełącznikiem `-c` | ||
|
||
::: info | ||
|
||
```shell | ||
./ksef -c config.yaml -log - ... | ||
``` | ||
|
||
::: | ||
|
||
::: warning | ||
Przełącznik -log jest bardzo ważny ponieważ odpowiada za przekierowanie wyjścia logów. Domyślnie jest ono wyłączone, nawet jeśli ustawisz poziomy logowania. Przykłady wywołań: | ||
|
||
przekierowanie logów do pliku | ||
|
||
```shell | ||
./ksef -c config.yaml -log plik-wyjscia.txt ... | ||
``` | ||
|
||
przekierowanie logów na stdout | ||
|
||
```shell | ||
./ksef -c config.yaml -log - ... | ||
``` | ||
|
||
::: | ||
|
||
## Dostępne loggery | ||
|
||
| logger | znaczenie | | ||
| ---------------- | ------------------------------------------- | | ||
| main | główny logger programu | | ||
| interactive | logger sesji interaktywnej | | ||
| interactive.http | logger sesji interaktywnej (zapytania HTTP) | | ||
| batch | logger sesji wsadowej | | ||
| batch.http | logger sesji wsadowej (zapytania HTTP) | | ||
| download | logger pobierania faktur | | ||
| download.http | logger pobierania faktur (zapytania HTTP) | | ||
| upload | logger wysyłki faktur | | ||
| upload.http | logger wysyłki faktur (zapytania HTTP) | | ||
| upo | logger pobierania UPO | | ||
| upo.http | logger pobierania UPO (zapytania HTTP) | | ||
|
||
## Tryb verbose | ||
|
||
Program obsługuje również tryb `verbose` (flaga `-v`) natomiast przestrzegam przed jej stosowaniem - generuje bardzo obszerne wyjście. Flaga `verbose` oznacza przełączenie wszystkich dostępnych loggerów na poziom `DEBUG` (tak, żebyś nie musiał robić tego ręcznie) | ||
|
||
::: info | ||
Przykład wywołania: | ||
|
||
```shell | ||
./ksef -v -log - ... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package logging | ||
|
||
import ( | ||
"io" | ||
"log/slog" | ||
) | ||
|
||
// these are the actual loggers that the program can reference | ||
// initialize the default values of the loggers so that they | ||
// become valid slog.Logger objects and so that we can use them | ||
// without exploding the code | ||
func defaultLogger() *slog.Logger { | ||
return slog.New( | ||
slog.NewTextHandler( | ||
io.Discard, | ||
&slog.HandlerOptions{ | ||
Level: slog.LevelInfo, | ||
}, | ||
), | ||
) | ||
} | ||
|
||
var SeiLogger *slog.Logger = defaultLogger() | ||
var GenerateLogger *slog.Logger = defaultLogger() | ||
var UploadLogger *slog.Logger = defaultLogger() | ||
var UploadHTTPLogger *slog.Logger = defaultLogger() | ||
var InteractiveLogger *slog.Logger = defaultLogger() | ||
var InteractiveHTTPLogger *slog.Logger = defaultLogger() | ||
var BatchLogger *slog.Logger = defaultLogger() | ||
var BatchHTTPLogger *slog.Logger = defaultLogger() | ||
var DownloadHTTPLogger *slog.Logger = defaultLogger() | ||
var DownloadLogger *slog.Logger = defaultLogger() | ||
var UPOLogger *slog.Logger = defaultLogger() | ||
var UPOHTTPLogger *slog.Logger = defaultLogger() | ||
var ParserLogger *slog.Logger = defaultLogger() | ||
|
||
func init() { | ||
// populate the helper map so that we can alter the loggers after config | ||
// is read. | ||
loggers = map[string]*slog.Logger{ | ||
"main": SeiLogger, | ||
"generate": GenerateLogger, | ||
"upload": UploadLogger, | ||
"upload.http": UploadHTTPLogger, | ||
"interactive": InteractiveLogger, | ||
"interactive.http": InteractiveHTTPLogger, | ||
"batch": BatchLogger, | ||
"batch.http": BatchHTTPLogger, | ||
"download": DownloadLogger, | ||
"download.http": DownloadHTTPLogger, | ||
"upo": UPOLogger, | ||
"upo.http": UPOHTTPLogger, | ||
"parser": ParserLogger, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.