Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Oct 16, 2018
0 parents commit eca70dc
Show file tree
Hide file tree
Showing 26 changed files with 1,345 additions and 0 deletions.
146 changes: 146 additions & 0 deletions .docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Monolog

[Monolog](https://github.com/Seldaek/monolog/) integration into [Nette/DI](https://github.com/nette/di)

See also [Monolog documentation](https://github.com/Seldaek/monolog#documentation), this is only an integration.

## Content

- [Installation - how to register](#installation)
- [Configuration - how to configure](#configuration)
- [Logging](#logging)
- [Logger manager](#loggermanager)
- [Logger holder](#loggerholder)
- [Bridges](#bridges)
- [Doctrine](#doctrine)

## Installation

```yaml
extensions:
monolog: Contributte\Monolog\DI\MonologExtension
```

## Configuration

```yaml
monolog:
tracy:
hook: true # use monolog inside tracy (required to log exceptions with monolog)
channel:
default: # default channel is required
handlers:
- Monolog\Handlers\RotatingFileHandler(%appDir%/../log/syslog.log, 30, Monolog\Logger::WARNING)
# you can use same configuration as in services section (with setup, type, arguments, etc.)
-
type: Monolog\Handler\RotatingFileHandler
arguments:
- %appDir%/../log/syslog.log
- 30
- Monolog\Logger::WARNING
processors:
- Monolog\Processor\MemoryPeakUsageProcessor()
```

## Logging

Log message with injected logger (only `default` is autowired)

```php
use Monolog\Logger;

class ExampleService
{

/** @var Logger **/
private $logger;

public function injectLogger(Logger $logger): void
{
$this->logger = $logger;
// or withName if you want change channel name
$this->logger = $logger->withName('example');
}

public function doSomething(): void
{
$this->logger->info('Log that application did something');
}

}
```

## LoggerManager

You could also use logger manager in case you need to use multiple logger at once.

```yaml
monolog:
manager:
enabled: false # disabled by default
lazy: true # lazy by default
```

```php
use Contributte\Monolog\ILoggerManager;

class ExampleService
{

/** @var ILoggerManager **/
private $logger;

public function injectLoggerManager(ILoggerManager $loggerManager): void
{
$this->loggerManager = $loggerManager;
}

public function doSomething(): void
{
$this->loggerManager->get('default')->info('Log that application did something');
$this->loggerManager->get('specialLogger')->info('Log something very special')
}

}
```

## LoggerHolder

Allow you get default logger statically in case that DIC is not available.

It add into message info about which class (or file) called LoggerHolder for easier debugging.

```yaml
monolog:
holder:
enabled: false # disabled by default
```

```php
use Contributte\Monolog\LoggerHolder;

class VerySpecialClassWithoutDependencyInjectionContainerAvailable
{

public function doSomething(): void
{
LoggerHolder::getInstance()->getLogger()->info('Log that application did something');
}

}
```

## Bridges

Bridges to other packages.

### Doctrine

Log all queries from doctrine/dbal

```yaml
# example for nettrine/dbal integration
dbal:
configuration:
sqlLogger: Contributte\Monolog\Bridges\DoctrineDbal\SqlLogger(@Monolog\Logger)
```
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: http://EditorConfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = tab
tab_width = 4

[{*.json,*.yml,*.md}]
indent_style = space
indent_size = 2
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Not archived
.docs export-ignore
tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
phpstan.neon export-ignore
README.md export-ignore
ruleset.xml export-ignore
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# IDE
/.idea

# Composer
/vendor
/composer.lock

# Tests
/temp
/coverage.xml
56 changes: 56 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
language: php
php:
- 7.1
- 7.2

# Don't build twice for PR (PR and push builds)
if: type != pull_request

before_install:
# Turn off XDebug
- phpenv config-rm xdebug.ini || return 0

install:
# Composer
- travis_retry composer install --no-progress --prefer-dist

script:
- composer run-script tests

jobs:
include:
- env: title="Lowest Dependencies 7.1"
php: 7.1
install:
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
script:
- composer run-script tests

- stage: Quality Assurance
php: 7.1
script:
- composer run-script qa

- stage: Phpstan
php: 7.1
script:
- composer run-script phpstan-install
- composer run-script phpstan

- stage: Test Coverage
if: branch = master AND type = push
php: 7.1
script:
- composer run-script coverage
after_script:
- wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar
- php php-coveralls.phar --verbose --config tests/.coveralls.yml

allow_failures:
- stage: Test Coverage

sudo: false

cache:
directories:
- $HOME/.composer/cache

0 comments on commit eca70dc

Please sign in to comment.