Skip to content

Commit 3acc50c

Browse files
authored
MCLOUD-5325: Move log section from .magento.env.yaml (magento#706)
1 parent d20b8bf commit 3acc50c

File tree

9 files changed

+118
-94
lines changed

9 files changed

+118
-94
lines changed

dist/.log.env.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
## Logging handlers
2+
3+
A logging handler pushes build and deploy logs to other systems. You can configure logging handlers to send messages to a remote logging server or to a messaging system like Slack or email.
4+
5+
### Send logs to a remote logging server
6+
7+
You can enable a _syslog_ handler, which is ideal for logging messages related to hardware, or a Graylog Extended Log Format (GELF) handler, which is ideal for logging messages from software applications.
8+
9+
The following example configures both of these handlers by adding the configuration to the `.magento.env.yaml` file.
10+
11+
```yaml
12+
log:
13+
syslog:
14+
ident: "<syslog-ident>"
15+
facility: 8 # http://php.net/manual/en/network.constants.php
16+
min_level: "info"
17+
logopts: <syslog-logopts>
18+
syslog_udp:
19+
host: "<syslog-host>"
20+
port: <syslog-port>
21+
facility: 8 # http://php.net/manual/en/network.constants.php
22+
ident: "<syslog-ident>"
23+
min_level: "info"
24+
gelf:
25+
min_level: "info"
26+
use_default_formatter: true
27+
additional: # Some additional information for each log message
28+
project: "<some-project-id>"
29+
app_id: "<some-app-id>"
30+
transport:
31+
http:
32+
host: "<http-host>"
33+
port: <http-port>
34+
path: "<http-path>"
35+
connection_timeout: 60
36+
tcp:
37+
host: "<tcp-host>"
38+
port: <tcp-port>
39+
connection_timeout: 60
40+
udp:
41+
host: "<udp-host>"
42+
port: <udp-port>
43+
chunk_size: 1024
44+
```
45+
### Send logs to a messaging system
46+
47+
Optionally, you can send logs to a messaging system, such as Slack or email, to receive real-time notifications.
48+
49+
**To configure Slack**:
50+
51+
```yaml
52+
log:
53+
slack:
54+
token: "<your-slack-token>"
55+
channel: "<your-slack-channel>"
56+
username: "SlackHandler"
57+
min_level: "info"
58+
```
59+
60+
- **token**— your Slack user token. Your user token authorizes Magento Commerce (Cloud) to send messages.
61+
- **channel**— name of the Slack channel Magento Commerce (Cloud) sends notifications.
62+
- **username**— username Magento Commerce (Cloud) uses to send notification messages in Slack.
63+
- **min_level**— minimum log level for notification messages. We recommend using info.
64+
65+
**To configure email**:
66+
67+
```yaml
68+
log:
69+
email:
70+
to: <your-email>
71+
from: <your-email>
72+
subject: "Log notification from Magento Cloud"
73+
min_level: "notice"
74+
```
75+
76+
- **to**— email address Magento Commerce (Cloud) sends notification messages.
77+
- **from**— email address for sending notification messages to recipients.
78+
- **subject**— description of the email.
79+
- **min_level**— minimum log level for notification messages. We recommend using notice or warning.
80+
-
81+
## Log levels
82+
83+
Log levels determine the level of detail in notification messages. The following log level categories include every log level below it. For example, a `debug` level includes logging from every level, whereas an `alert` level only shows alerts and emergencies.
84+
85+
- **debug**—detailed debug information
86+
- **info**—interesting events, such as a user login or SQL log
87+
- **notice**—normal, but significant events
88+
- **warning**—exceptional occurrences that are not errors, such as the use of a deprecated API or poor use of an API
89+
- **error**—run-time errors that do not require immediate action
90+
- **critical**—critical conditions, such as an unavailable application component or an unexpected exception
91+
- **alert**—immediate action required—such as a website is down or the database is unavailable—that triggers an SMS alert
92+
- **emergency**—system is unusable

dist/.magento.env.yaml

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/Command/GenerateSchema.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public function execute(InputInterface $input, OutputInterface $output)
8686

8787
$this->file->filePutContents(
8888
$this->fileList->getEnvDistConfig(),
89-
$this->formatter->format($data)
89+
$this->formatter->format($data) . PHP_EOL
90+
. $this->file->fileGetContents($this->fileList->getLogDistConfig())
9091
);
9192

9293
$output->writeln(sprintf('Dist file was successfully generated: %s', $this->fileList->getEnvDistConfig()));

src/Config/Schema/Formatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function format(array $data): string
4747
$magentoVersion = $item[Schema::SCHEMA_MAGENTO_VERSION] ?? '>=' . MagentoVersion::MIN_VERSION;
4848

4949
$text .= sprintf(
50-
'## %s%s%s%s',
50+
'### %s%s%s%s',
5151
$key,
5252
self::EMPTY_LINE,
5353
wordwrap($description, 120),
@@ -72,7 +72,7 @@ public function format(array $data): string
7272
$text .= "\n";
7373

7474
if (!empty($item[Schema::SCHEMA_EXAMPLES])) {
75-
$text .= '### Examples' . self::EMPTY_LINE;
75+
$text .= 'Examples' . self::EMPTY_LINE;
7676

7777
foreach ($item[Schema::SCHEMA_EXAMPLES] as $example) {
7878
if (!empty($example[Schema::SCHEMA_EXAMPLE_COMMENT])) {

src/Filesystem/FileList.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ public function getEnvDistConfig(): string
132132
return $this->directoryList->getMagentoRoot() . '/.magento.env.md';
133133
}
134134

135+
/**
136+
* @return string
137+
*/
138+
public function getLogDistConfig(): string
139+
{
140+
return $this->directoryList->getRoot() . '/dist/.log.env.md';
141+
}
142+
135143
/**
136144
* @return string
137145
*/

src/Test/Functional/Acceptance/CronCest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function testCron(\CliTester $I, \Codeception\Example $data): void
3939
$I->runDockerComposeCommand('run build cloud-build');
4040
$I->startEnvironment();
4141
$I->runDockerComposeCommand('run deploy cloud-deploy');
42+
$I->runDockerComposeCommand('run deploy cloud-post-deploy');
4243
$I->deleteFromDatabase('cron_schedule');
4344
$I->runDockerComposeCommand('run deploy magento-command cron:run');
4445
$I->runDockerComposeCommand('run deploy magento-command cron:run');

src/Test/Unit/Command/GenerateSchemaTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,16 @@ public function testExecute(): void
7777
->willReturn(['some' => 'schema']);
7878
$this->fileListMock->method('getEnvDistConfig')
7979
->willReturn('.magento.env.md');
80+
$this->fileListMock->method('getLogDistConfig')
81+
->willReturn('/dist/.log.env.md');
8082
$this->formatterMock->method('format')
8183
->with(['some' => 'schema'])
8284
->willReturn('some schema');
85+
$this->fileMock->expects($this->once())
86+
->method('fileGetContents')
87+
->willReturn('some additional text');
8388
$this->fileMock->method('filePutContents')
84-
->with('.magento.env.md', 'some schema');
89+
->with('.magento.env.md', 'some schema' . PHP_EOL . 'some additional text');
8590

8691
$this->command->execute($input, $output);
8792
}

src/Test/Unit/Config/Schema/_files/.magento.env.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## ENV_VARIABLE
1+
### ENV_VARIABLE
22

33
Some description
44

@@ -8,7 +8,7 @@ Some description
88
|Magento version|\>=2.1.24|
99
|Stages|global|
1010

11-
### Examples
11+
Examples
1212

1313
```yaml
1414
'Some example 1'

src/Test/Unit/Filesystem/FileListTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,9 @@ public function testGetEnvDistConfig(): void
125125
{
126126
$this->assertSame('magento_root/.magento.env.md', $this->fileList->getEnvDistConfig());
127127
}
128+
129+
public function testGetLogDistConfig(): void
130+
{
131+
$this->assertSame('root/dist/.log.env.md', $this->fileList->getLogDistConfig());
132+
}
128133
}

0 commit comments

Comments
 (0)