Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it should work on PhpShtorm? #31

Closed
mubat opened this issue Feb 22, 2018 · 4 comments
Closed

Is it should work on PhpShtorm? #31

mubat opened this issue Feb 22, 2018 · 4 comments

Comments

@mubat
Copy link

mubat commented Feb 22, 2018

I tried to use plugin at PhpShtorm 2017.3 in Yii php project.
I created new log format:

Pattern (?im)^([\d-: ]+)[((?:\d{1,3}.){3}\d{1,3})][-][-][(\w+)][([\w\:\d]+)] (.*)
Message start pattern ^\d
Time format yyyy-MM-dd HH:mm:ss

Standard log record at Yii project seems like:

2017-09-27 14:52:49 [127.0.0.1][-][-][error][yii\base\UnknownPropertyException] yii\base\UnknownPropertyException: Getting unknown property: api\modules\v1\models\General::district.name in /home/oleg/Projects/crm-application/vendor/yiisoft/yii2/base/Component.php:143
Stack trace:
#0 /home/oleg/Projects/crm-application/vendor/yiisoft/yii2/db/BaseActiveRecord.php(286): yii\base\Component->__get('district.name')
#1 /home/oleg/Projects/crm-application/vendor/yiisoft/yii2/base/ArrayableTrait.php(120): yii\db\BaseActiveRecord->__get('district.name')
#2 /home/oleg/Projects/crm-application/vendor/yiisoft/yii2/rest/Serializer.php(292): yii\base\Model->toArray(Array, Array)
#3 /home/oleg/Projects/crm-application/vendor/yiisoft/yii2/rest/Serializer.php(188): yii\rest\Serializer->serializeModels(Array)
#4 /home/oleg/Projects/crm-application/vendor/yiisoft/yii2/rest/Serializer.php(152): yii\rest\Serializer->serializeDataProvider(Object(yii\data\ActiveDataProvider))
#5 /home/oleg/Projects/crm-application/vendor/yiisoft/yii2/rest/Controller.php(97): yii\rest\Serializer->serialize(Object(yii\data\ActiveDataProvider))
#6 /home/oleg/Projects/crm-application/vendor/yiisoft/yii2/rest/Controller.php(75): yii\rest\Controller->serializeData(Object(yii\data\ActiveDataProvider))
#7 /home/oleg/Projects/crm-application/vendor/yiisoft/yii2/base/Controller.php(156): yii\rest\Controller->afterAction(Object(yii\rest\IndexAction), Object(yii\data\ActiveDataProvider))
#8 /home/oleg/Projects/crm-application/vendor/yiisoft/yii2/base/Module.php(454): yii\base\Controller->runAction('index', Array)
#9 /home/oleg/Projects/crm-application/vendor/yiisoft/yii2/web/Application.php(100): yii\base\Module->runAction('v1/object/index', Array)
#10 /home/oleg/Projects/crm-application/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#11 /home/oleg/Projects/crm-application/api/web/index.php(18): yii\base\Application->run()
#12 {main}
2017-09-27 14:52:49 [127.0.0.1][-][-][info][application] $_SERVER = [
    'REDIRECT_REDIRECT_STATUS' => '200'
    'REDIRECT_STATUS' => '200'
    'HTTP_USER_AGENT' => 'ApiDebugger v2.0.1'
    'HTTP_HOST' => 'crm.dev'
    'HTTP_CONNECTION' => 'Keep-Alive'
    'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
    'SERVER_SIGNATURE' => '<address>Apache/2.4.18 (Ubuntu) Server at crm.dev Port 80</address>
'
    'SERVER_SOFTWARE' => 'Apache/2.4.18 (Ubuntu)'
    'SERVER_NAME' => 'crm.dev'
    'SERVER_ADDR' => '127.0.0.1'
    'SERVER_PORT' => '80'
    'REMOTE_ADDR' => '127.0.0.1'
    'DOCUMENT_ROOT' => '/home/oleg/Projects/crm-application/'
    'REQUEST_SCHEME' => 'http'
    'CONTEXT_PREFIX' => ''
    'CONTEXT_DOCUMENT_ROOT' => '/home/oleg/Projects/crm-application/'
    'SERVER_ADMIN' => 'webmaster@localhost'
    'SCRIPT_FILENAME' => '/home/oleg/Projects/crm-application/api/web/index.php'
    'REMOTE_PORT' => '34204'
    'REDIRECT_URL' => '/api/web//v1/object'
    'GATEWAY_INTERFACE' => 'CGI/1.1'
    'SERVER_PROTOCOL' => 'HTTP/1.1'
    'REQUEST_METHOD' => 'GET'
    'QUERY_STRING' => ''
    'REQUEST_URI' => '/api/v1/object'
    'SCRIPT_NAME' => '/api/web/index.php'
    'PHP_SELF' => '/api/web/index.php'
    'REQUEST_TIME_FLOAT' => 1506523969.49
    'REQUEST_TIME' => 1506523969
]

I check pattern at online regex tester and it works: https://www.ocpsoft.org/tutorials/regular-expressions/java-visual-regex-tester/

Is it should works? Is it an issue?

@knah
Copy link
Collaborator

knah commented Feb 22, 2018

I have no idea what your visual regex tester does wrong, but your regex suffers from extreme lack of escaping. It doesn't even work with your pattern and log sample for me.

The correct regex that matches both messages provided by you is ^([\d-: ]+)\[((?:\d{1,3}.){3}\d{1,3})\]\[\-\]\[\-\]\[(\w+)\]\[([\w\:\d\\]+)\] (.*). Note that all square braces that do not denote a character class are escaped. I also added a backslash to category capture group so that it matches yii\base\UnknownPropertyException.

That aside, we are planning to add visual regex validation and testing aids to Ideolog sometime soon.

@knah knah closed this as completed Feb 22, 2018
@mubat
Copy link
Author

mubat commented Feb 22, 2018

@knah How plugin should be configured?
What means Patterns settings block? Is patterns inside it should include previous data, or only validate category group?
screenshot from 2018-02-22 11-32-54
screenshot from 2018-02-22 11-33-11

@knah
Copy link
Collaborator

knah commented Feb 22, 2018

"Patterns" specify how to highlight your logs. See #29 and https://github.com/JetBrains/ideolog/wiki/Highlighting-Patterns for more info.

@khalwat
Copy link

khalwat commented Sep 19, 2020

I realize this is a super-old thread, but in case anyone else finds it -- here's a regex that works with Yii2 (and thus Craft CMS) logs:

Message pattern:

^([\d-: ]+)\[(.*?)\]\[(.*?)\]\[(.*?)\]\[(.*?)\]\[(.*?)\] (.*)

Message start pattern:

^\d

Time format:

yyyy-MM-dd HH:mm:ss

Time capture group:

1

Severity capture group:

5

Category capture group:

4

Screen Shot 2020-09-18 at 3 56 40 PM

...and then for the Patterns, you'll want to add a couple:

Profile:

^\s*p(rofile.*)?\s*$

Debug:

^\s*d(ebug)?\s*$

Screen Shot 2020-09-19 at 10 20 24 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants