regex to search multiple pattern - python-3.7

Edited my code, tried a different approach to get the desired output.
Let me know if it's correct
import re
pattern1 = re.compile(r'\b(ERROR)')
pattern2 = re.compile(r'^\d+-\d+-\d+')
count =0
with open('sample.txt',encoding='utf-8')as f:
for i in f:
a= re.search(pattern1,i)
if a:
count = count + 1
b = re.search(pattern2,i)
if b:
print(b.group(),':',a.group())
print('Total ERROR in the logfile:',count)
***output:***
2019-11-22 : ERROR
2019-11-22 : ERROR
2019-11-20 : ERROR
Total ERROR in the logfile: 3
log.txt
2019-11-22 16:46:46,985 - main - INFO - Starting to Wait for Files
2019-11-22 16:46:56,645 - main - INFO - Starting: Attempt 1 Checking for New Files
2019-11-22 16:47:46,488 - main - INFO - Success: Downloading the Files from Cloud Storage: Return
2019-11-22 16:48:48,180 - main - ERROR - Failed: Waiting for files the Files
2019-11-22 16:49:17,918 - main - INFO - Starting to Wait for Files
2019-11-22 16:49:32,160 - main - INFO - Starting: Attempt 1 Checking for New Files
2019-11-22 16:49:39,329 - main - WARNING - Success: Downloading the Files from Cloud Storage:
2019-11-22 16:53:30,706 - main - WARNING - Starting to Wait for Files
2019-11-22 16:53:48,180 - main - ERROR - Failed: Waiting for files the Files
2019-11-20 10:00:00,121 - main - ERROR - Failed: Waiting for files the Files

The pattern you should be using to match error lines is:
^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\bERROR\b.*$
Your updated script:
pattern1 = re.compile(r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\bERROR\b.*$')
count = 0
with open('log.txt',encoding='utf-8')as f:
for i in f:
a = re.search(pattern1, i)
if a:
count = count + 1

Related

SwiftLint warning: Configuration contains invalid keys: ["function_level"]

Jus updated pods and getting warning
warning: Configuration contains invalid keys:
["function_level"]
changed .swiftlint.yml according to CHANGELOG
inside: .swiftlint.yml
colon:
severity: error
line_length:
ignores_comments: true
warning: 260
error: 300
type_body_length:
warning: 300
error: 500
file_length:
warning: 800
error: 1000
function_parameter_count:
warning: 20
error: 30
function_body_length:
warning: 120
error: 150
cyclomatic_complexity:
warning: 40
error: 50
disabled_rules:
- implicit_getter
- redundant_string_enum_value
nesting:
type_level:
warning: 3
error: 6
function_level:
warning: 5
error: 10
#implicitly_unwrapped_optional:
# severity: warning
force_unwrapping:
severity: error
vertical_whitespace:
severity: error
#optional_try:
# severity: error
force_try:
severity: error
type_name:
min_length: 3
max_length: 60
error: 80
identifier_name:
min_length: 1
max_length: 60
excluded:
- id
# Disable rules from the default enabled set.
disabled_rules:
- trailing_whitespace
- implicit_getter
- redundant_string_enum_value
- switch_case_alignment
# Enable rules not from the default set.
opt_in_rules:
# - function_default_parameter_at_end
- empty_count
# - index_at_zero
- legacy_constant
# - implicitly_unwrapped_optional
- force_unwrapping
# Acts as a whitelist, only the rules specified in this list will be enabled. Can not be specified alongside disabled_rules or opt_in_rules.
only_rules:
# This is an entirely separate list of rules that are only run by the analyze command. All analyzer rules are opt-in, so this is the only configurable rule list (there is no disabled/whitelist equivalent).
analyzer_rules:
# This section is for defining custom rules
# custom_rules:
# constant_zero:
# included: ".*\\.swift"
# excluded: ".*Test\\.swift"
# name: "Constant Zero"
# regex: "(^0$)"
# match_kinds:
# - number
# message: "Use .zero instead of 0"
# severity: warning
# optional_try:
# included: ".*\\.swift"
# excluded: ".*Test\\.swift"
# name: "Optional Try"
# regex: ".*try?.*"
# match_kinds:
# - idiomatic
# message: "Optional tries should be avoided."
# severity: warning
# paths to ignore during linting. Takes precedence over `included`.
excluded:
- Carthage
- Pods

How to avoid looped Pentaho job logging "Finished job entry" rows multiple times?

I have created looped Pentaho(v8.1) job, It circles in every 15 seconds and entire job works about 7 minutes, but after 5 or 6 minutes I get thousands of similar rows in log field with texts : "Finished job entry"
like this
2019/03/28 11:47:49 - FILLALLACC_MAIN_WF - Finished job entry [Table input 3] (result=[true])
2019/03/28 11:47:49 - FILLALLACC_MAIN_WF - Finished job entry [Simple evaluation duration] (result=[true])
2019/03/28 11:47:49 - FILLALLACC_MAIN_WF - Finished job entry [SET PROCESS_STATUS 0] (result=[true])
2019/03/28 11:47:49 - FILLALLACC_MAIN_WF - Finished job entry [SEND CLIENTS&ACCOUNTS] (result=[true])
2019/03/28 11:47:49 - FILLALLACC_MAIN_WF - Finished job entry [FILL ALL ACCOUNTS] (result=[true])
2019/03/28 11:47:49 - FILLALLACC_MAIN_WF - Finished job entry [Wait for] (result=[true])
2019/03/28 11:47:49 - FILLALLACC_MAIN_WF - Finished job entry [SET PROCESS_STATUS 2] (result=[true])
2019/03/28 11:47:49 - FILLALLACC_MAIN_WF - Finished job entry [call procedure] (result=[true])
2019/03/28 11:47:49 - FILLALLACC_MAIN_WF - Finished job entry [SET PROCESS_STATUS 1] (result=[true])
...
How can I avoid logging this looped "Finished job entry" rows?
Try "Minimal" or "Error" log level when starting the job.
Otherwise, there's no way to suppress these messages. These are simply telling you what's going on in your job loops.

How to integrate Vaadin 7.3.9 into a Grails project in Eclipse?

I am experiencing some troubles with the Vaadin integration into a Grails project in Eclipse.
I am using the Eclipse (version 4.4 Luna) provided by Spring Tool Suite (version 3.6.3) and Grails (version 2.4.4).
I create a Grails project:
File -> New -> Grails Project
I am reading the Vaadin Cookbook book, the author says that in order to use Vaadin in a Grails project, the Vaadin plugin for Grails must be installed. The author says that one should:
Open the grails console and type:
grails> install-plugin vaadin
However, this is deprecated as of Grails 2.4.3, and the plugin must be added to the BuildConfig.groovy file like this (basing on this tutorial of one of the co-authors of the book -> https://vaadin.com/wiki/-/wiki/Main/Vaadin%20on%20Grails%20-%20Create%20project%20in%20IntelliJ%20IDEA (IntelliJIDEA is used in the linked URL instead of Eclipse)):
// BuildConfig.groovy
// ...
grails.project.dependency.resolution = {
//...
plugins {
//...
compile ":vaadin:7.3.9"
//...
}
}
But then, what should I do? In the book they say that the grails-app/vaadin folder must be marked as the source folder (Build Path -> Use as source folder), but there's no such folder in my Grails project.
Also, from the tutorial with InlliJIDEA linked above, the author says:
Now I have tried to edit the UrlMappings.groovy file in order to remove all the mappings:
class UrlMappings {
static mappings = {
}
}
And then when I run the run-app command I get the following exception:
|Running Grails application
objc[42370]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
| Error 2015-01-30 11:33:56,213 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
Line | Method
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by IntegrationException: Error activating Bean Validation integration
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by NoClassDefFoundError: javax/validation/ParameterNameProvider
->> 760 | defineClass in java.lang.ClassLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 142 | defineClass in java.security.SecureClassLoader
| 455 | defineClass in java.net.URLClassLoader
| 73 | access$100 in ''
| 367 | run . . . in java.net.URLClassLoader$1
| 361 | run in ''
| 360 | findClass in java.net.URLClassLoader
| 424 | loadClass in java.lang.ClassLoader
| 269 | configure in javax.validation.Validation$GenericBootstrapImpl
| 111 | buildDefaultValidatorFactory in javax.validation.Validation
| 266 | run . . . in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by ClassNotFoundException: javax.validation.ParameterNameProvider
->> 372 | run in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 361 | run in ''
| 360 | findClass in java.net.URLClassLoader
| 424 | loadClass in java.lang.ClassLoader
| 760 | defineClass in ''
| 142 | defineClass in java.security.SecureClassLoader
| 455 | defineClass in java.net.URLClassLoader
| 73 | access$100 in ''
| 367 | run . . . in java.net.URLClassLoader$1
| 361 | run in ''
| 360 | findClass in java.net.URLClassLoader
| 424 | loadClass in java.lang.ClassLoader
| 269 | configure in javax.validation.Validation$GenericBootstrapImpl
| 111 | buildDefaultValidatorFactory in javax.validation.Validation
| 266 | run . . . in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Error |
Forked Grails VM exited with error
|Server running. Browse to http://localhost:8080/vaadin-in-grails
It says "Server running" at the end but it is not true, and no grails-app/vaadin folder is created as needed.
I didn't find any other tutorials which cover the topic (specifically I was searching for an Eclipse version of the IntelliJIDEA tutorial I linked, but didn't find it).
So, as I know that the book I am reading covers an older version of Grails where plugins are installed via the install-plugin deprecated command and I can't use it and as I have tried to use the compile ":vaadin:7.3.9" directive without success, I am asking someone of SO here.
How can I resolve this issue and start programming with Grails/Vaadin?
Don't use the install-plugin method.
Place this in the plugins section in BuildConfig.groovy:
compile ":vaadin:7.4.1"
From what I understand from the plugin author, the newer versions of the Vaadin/Grails plugin no longer create the grails-app/vaadin directory. Instead, you're now expected to place your vaadin code in the typical src/groovy or src/java folders.
Buddy, I had the same problem but after reading a lot the book Vaadin on Grails and experimenting a lot I came across with the solution, it's important to mention that my grails project is using this configurations, no major changes in version so I believe it should work:
Grails 2.4.5
Vaadin 7.4.8, which is a bit newer,
Oracle Express for Database (this is agnostic)
From your log trace, I see this line:
Caused by ClassNotFoundException: javax.validation.ParameterNameProvider
OK, first things first, go to your BuildConfig.groovy and set this values:
//BuildConfig.groovy
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// runtime 'mysql:mysql-connector-java:5.1.29'
// runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
compile 'javax.validation:validation-api:1.1.0.Final'
test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
}
plugins {
// plugins for the build system only
build ":tomcat:7.0.55.2" // or ":tomcat:8.0.20"
// plugins for the compile step
//compile ":scaffolding:2.1.2"
compile ':cache:1.1.8'
compile ":asset-pipeline:2.1.5"
compile ":vaadin:7.4.8"
// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.6.1"
runtime ":database-migration:1.4.0"
//runtime ":jquery:1.11.1"
}
What you have to notice from above code are two things:
Plugins section is using hibernate4:4.3.6.1
In Dependencies section I added following line, from my many reads some people mentioned that due the change from Hibernate3 to Hibernate4 there were some changes in the specification in order to meet some standards (here the javax.validation API was deprecated), so this is the line that solves your problem:
compile 'javax.validation:validation-api:1.1.0.Final'
Now in your file DataSource.groovy, take care of this points:
1. As you remember I set project to use Hibernate4, so the propper configuration should be done.
//DataSource.groovy
dataSource {
pooled = true
jmxExport = true
username = "db_user"
password = "db_password"
dialect = org.hibernate.dialect.Oracle10gDialect
driverClassName = 'oracle.jdbc.OracleDriver'
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
// cache.region.factory_class = 'org.hibernate.cache.SingletonEhCacheRegionFactory' // Hibernate 3
cache.region.factory_class = 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' // Hibernate 4
singleSession = true // configure OSIV singleSession mode
flush.mode = 'manual' // OSIV session flush mode outside of transactional context
jdbc.use_get_generated_keys = true
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
//url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:oracle:thin:#localhost:1521:xe"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:oracle:thin:#localhost:1521:xe"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:oracle:thin:#localhost:1521:xe"
properties {
// See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
jmxEnabled = true
initialSize = 5
maxActive = 50
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}
}
}
Inside the section hibernate you have to set the value for:
cache.region.factory_class
In my case I'm using Hibernate4, so you should use the same value.
Sources:
Check this project out: https://github.com/vaadin-on-grails/sass-compilation and don't forget to buy the book Vaadin on Grails, it has lots of information related.

How to record FATAL events to separate file with log4perl

I'm using log4perl and I want to record all FATAL events in the separate file.
Here is my script:
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use Log::Log4perl qw(get_logger);
Log::Log4perl::init('log4perl.conf');
my $l_aa = get_logger('AA');
$l_aa->fatal('fatal');
my $l_bb = get_logger('BB');
$l_bb->info('info');
And here is my config file:
## What to log
log4perl.logger = FATAL, FatalLog
log4perl.logger.BB = INFO, MainLog
## Logger MainLog
log4perl.appender.MainLog = Log::Log4perl::Appender::File
log4perl.appender.MainLog.filename = log4perl_main.log
log4perl.appender.MainLog.layout = PatternLayout
log4perl.appender.MainLog.layout.ConversionPattern = \
[%d{yyyy-MM-dd HH:mm:ss}] %p - %c - %m%n
## Logger FatalLog
log4perl.appender.FatalLog = Log::Log4perl::Appender::File
log4perl.appender.FatalLog.filename = log4perl_fatal.log
log4perl.appender.FatalLog.layout = PatternLayout
log4perl.appender.FatalLog.layout.ConversionPattern = \
[%d{yyyy-MM-dd HH:mm:ss}] %p - %c - %m%n
I'm expecting that with this setup the file log4perl_fatal.log will get only FATAL-level events. But here is what I get after running the script:
$ tail -f *log
==> log4perl_fatal.log <==
[2014-04-13 08:41:22] FATAL - AA - fatal
[2014-04-13 08:41:22] INFO - BB - info
==> log4perl_main.log <==
[2014-04-13 08:41:22] INFO - BB - info
Why I'm getting INFO-level event in log4perl_fatal.log?
How can I recordy only FATAL-level events in the separate file?
PS Here is a GitHub repo with this script & config.
Your conf file has the following line:
log4perl.logger = FATAL, FatalLog
what you need is the following:
log4perl.logger.AA = FATAL, FatalLog
Otherwise, the FatalLog becomes a catch-all for both loggers, instead of isolated to this instance:
my $l_aa = get_logger('AA');
This is the question that is coverd in log4perl FAQ — https://metacpan.org/pod/Log::Log4perl::FAQ#How-can-I-collect-all-FATAL-messages-in-an-extra-log-file
In the example log4perl_fatal.log gets INFO level events because of appender additivity.
To fix it this line should be added to config file:
log4perl.appender.FatalLog.Threshold = FATAL
Then the output files get the expected output:
$ tail log4perl*log
==> log4perl_fatal.log <==
[2014-05-04 20:00:39] FATAL - AA - fatal
==> log4perl_main.log <==
[2014-05-04 20:00:39] INFO - BB - info

Grails MongoDB NoSuchFieldError: ACKNOWLEDGED

Getting error on update when using a different version mongodb java client.
I ran the dependency-report and found that only 1 jar for mongdb java driver is existing.
Please guide why this error is coming, I am trying to update domain object through GORM.
dependencies {
runtime "org.mongodb:mongo-java-driver:2.9.0"
}
plugins {
compile (":mongodb:1.3.0"){
excludes "mongo-java-driver";
}
}
Message: ACKNOWLEDGED
Line | Method
->> 646 | doInDB in
org.grails.datastore.mapping.mongo.engine.MongoEntityPersister$5
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 616 | updateEntry in
org.grails.datastore.mapping.mongo.engine.MongoEntityPersister
| 78 | updateEntry . . . . . . in ''
| 846 | run in
org.grails.datastore.mapping.engine.NativeEntryEntityPersister$2
| 33 | executePendingOperation in
org.grails.datastore.mapping.core.impl.PendingOperationExecution
| 364 | flushPendingOperations in org.grails.datastore.mapping.core.AbstractSession
| 343 | flushPendingUpdates . . in ''
| 263 | flush in ''
| 126 | flush . . . . . . . . . in org.grails.datastore.mapping.mongo.MongoSession
WriteConcern.ACKNOWLEDGED is only available in the MongoDB Java Driver version 2.10 and above. You either need to update your Mongo version:
dependencies {
runtime "org.mongodb:mongo-java-driver:2.10.0"
}
or you need to remove your exclusion of the mongo driver here:
compile (":mongodb:1.3.0"){
excludes "mongo-java-driver";
}
and replace it with:
compile ":mongodb:1.3.0"
If you take this second option, this will use the 2.11 version of the Mongo Java Driver, which is what this plugin code is expecting. Using a version of the driver that is older than 2.11 is likely to cause these sorts of issues.