Apache Mesos
log4j.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __ORG_APACHE_LOG4J_HPP__
18 #define __ORG_APACHE_LOG4J_HPP__
19 
20 #include <jvm/jvm.hpp>
21 
22 namespace org {
23 namespace apache {
24 namespace log4j {
25 
26 // Forward declaration.
27 extern const char LEVEL_OFF_SIGNATURE[];
28 extern const char LEVEL_OFF[];
29 
30 
31 class Level : public Jvm::Object // TODO(benh): Extends Priority.
32 {
33 public:
34  friend class Jvm::StaticVariable<Level, LEVEL_OFF, LEVEL_OFF_SIGNATURE>;
35 
37 
38  Level() {} // No default constuctors.
39 };
40 
41 
42 class Category : public Jvm::Object
43 {
44 public:
45  void setLevel(const Level& level)
46  {
47  static Jvm::Method method = Jvm::get()->findMethod(
48  Jvm::Class::named("org/apache/log4j/Category")
49  .method("setLevel")
50  .parameter(Jvm::Class::named("org/apache/log4j/Level"))
51  .returns(Jvm::get()->voidClass));
52 
53  Jvm::get()->invoke<void>(object, method, (jobject) level);
54  }
55 
56 protected:
57  Category() {} // No default constructors.
58 };
59 
60 
61 class Logger : public Category
62 {
63 public:
65  {
66  static Jvm::Method method = Jvm::get()->findStaticMethod(
67  Jvm::Class::named("org/apache/log4j/Logger")
68  .method("getRootLogger")
69  .returns(Jvm::Class::named("org/apache/log4j/Logger")));
70 
71  Logger logger;
72  logger.object = Jvm::get()->invokeStatic<jobject>(method);
73 
74  return logger;
75  }
76 
77 protected:
78  Logger() {} // No default constructors.
79 };
80 
81 
82 } // namespace log4j {
83 } // namespace apache {
84 } // namespace org {
85 
86 #endif // __ORG_APACHE_LOG4J_HPP__
Definition: log4j.hpp:42
Definition: log4j.hpp:22
Logger()
Definition: log4j.hpp:78
Definition: log4j.hpp:31
const char LEVEL_OFF[]
Method findStaticMethod(const MethodSignature &signature)
Method findMethod(const MethodSignature &signature)
Definition: jvm.hpp:208
Definition: jvm.hpp:244
static Jvm * get()
jobject object
Definition: jvm.hpp:287
T invokeStatic(const Method method,...)
Definition: jvm.hpp:501
void setLevel(const Level &level)
Definition: log4j.hpp:45
Definition: log4j.hpp:61
const char LEVEL_OFF_SIGNATURE[]
Definition: jvm.hpp:347
jobject invoke(const Constructor ctor,...)
static const Class named(const std::string &name)
static Logger getRootLogger()
Definition: log4j.hpp:64
Level()
Definition: log4j.hpp:38
static Jvm::StaticVariable< Level, LEVEL_OFF, LEVEL_OFF_SIGNATURE > OFF
Definition: log4j.hpp:36
Category()
Definition: log4j.hpp:57