Skip to content

Commit 15b6ab3

Browse files
committed
Merge branch 'feature/logging'
2 parents dad0995 + 76a7bb4 commit 15b6ab3

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

logging.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
2+
.level = FINEST
3+
4+
java.util.logging.ConsoleHandler.level = FINE
5+
6+
java.util.logging.FileHandler.level = FINER
7+
java.util.logging.FileHandler.level = formatter
8+
java.util.logging.FileHandler.limit = 524288
9+
java.util.logging.FileHandler.count = 100
10+
java.util.logging.FileHandler.pattern = test/results/logs/parser_%g.log
11+
java.util.logging.FileHandler.append = true

src/fortran/ofp/XMLPrinter.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.ArrayList;
44
import java.util.Arrays;
5+
import java.util.logging.Level;
6+
import java.util.logging.Logger;
57

68
import org.antlr.runtime.Token;
79
import org.w3c.dom.Attr;
@@ -17,6 +19,8 @@
1719
*/
1820
public class XMLPrinter extends XMLPrinterBase {
1921

22+
private static final Logger LOG = Logger.getLogger(XMLPrinter.class.getName());
23+
2024
public XMLPrinter(String[] args, IFortranParser parser, String filename) {
2125
super(args, parser, filename);
2226
}
@@ -93,8 +97,10 @@ public void specification_part(int numUseStmts, int numImportStmts, int numImplS
9397
contextClose("header");
9498
contextOpen("body");
9599
}
96-
if (context.getTagName().equals("declaration"))
100+
if (context.getTagName().equals("declaration")) {
101+
LOG.log(Level.FINER, "closing unclosed declaration at specification_part");
97102
contextClose("declaration");
103+
}
98104
if (!context.getTagName().equals("specification"))
99105
contextOpen("specification");
100106
contextCloseAllInner("specification");
@@ -2263,8 +2269,10 @@ public void module_subprogram(boolean hasPrefix) {
22632269

22642270
public void use_stmt(Token label, Token useKeyword, Token id, Token onlyKeyword, Token eos, boolean hasModuleNature,
22652271
boolean hasRenameList, boolean hasOnly) {
2266-
if (context.getTagName().equals("declaration"))
2272+
if (context.getTagName().equals("declaration")) {
2273+
LOG.log(Level.FINE, "closing unclosed declaration at use_stmt id={0}", id.getText());
22672274
contextClose("declaration");
2275+
}
22682276
if (!context.getTagName().equals("use"))
22692277
contextOpen("use");
22702278
setAttribute("name", id);
@@ -2274,8 +2282,10 @@ public void use_stmt(Token label, Token useKeyword, Token id, Token onlyKeyword,
22742282
}
22752283

22762284
public void rename_list__begin() {
2277-
if (context.getTagName().equals("declaration"))
2285+
if (context.getTagName().equals("declaration")) {
2286+
LOG.log(Level.FINE, "closing unclosed declaration at rename_list__begin");
22782287
contextClose("declaration");
2288+
}
22792289
contextOpen("use");
22802290
contextOpen("rename");
22812291
if (verbosity >= 100)
@@ -2288,8 +2298,10 @@ public void rename_list(int count) {
22882298
}
22892299

22902300
public void only_list__begin() {
2291-
if (context.getTagName().equals("declaration"))
2301+
if (context.getTagName().equals("declaration")) {
2302+
LOG.log(Level.FINE, "closing unclosed declaration at only_list__begin");
22922303
contextClose("declaration");
2304+
}
22932305
contextOpen("use");
22942306
contextOpen("only");
22952307
if (verbosity >= 100)
@@ -2630,8 +2642,10 @@ public void end_mp_subprogram_stmt(Token label, Token keyword1, Token keyword2,
26302642

26312643
public void start_of_file(String filename, String path) {
26322644
if (contextTryFind("file") != null) {
2633-
if (context.getTagName().equals("declaration"))
2645+
if (context.getTagName().equals("declaration")) {
2646+
LOG.log(Level.FINER, "closing unclosed declaration at start_of_file");
26342647
contextClose("declaration");
2648+
}
26352649
contextOpen("declaration");
26362650
setAttribute("type", "include");
26372651
}

test/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
from open_fortran_parser.config import JAVA as java_config
77

88

9+
if java_config['options'] is None:
10+
java_config['options'] = []
11+
java_config['options'].append('-Djava.util.logging.config.file=logging.properties')
12+
13+
os.makedirs(str(pathlib.Path('test', 'results', 'logs')), exist_ok=True)
14+
915
if os.environ.get('TEST_COVERAGE'):
1016
JACOCO_PATH = pathlib.Path('lib', 'org.jacoco.agent-0.8.1-runtime.jar').resolve()
1117
JACOCO_EXCLUDES = ('fortran.ofp.parser.java.FortranParserExtras_FortranParser08',)
1218
if JACOCO_PATH.is_file():
13-
if java_config['options'] is None:
14-
java_config['options'] = []
1519
java_config['options'].append(
1620
'-javaagent:{}=excludes={}'.format(str(JACOCO_PATH), ':'.join(JACOCO_EXCLUDES)))

0 commit comments

Comments
 (0)